| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,164 @@ | |||
| 1 | + # Lista Enlazada (Linked List) | ||
| 2 | + | ||
| 3 | + _Lee esto en otros idiomas:_ | ||
| 4 | + [_简体中文_](README.zh-CN.md), | ||
| 5 | + [_Русский_](README.ru-RU.md), | ||
| 6 | + [_日本語_](README.ja-JP.md), | ||
| 7 | + [_Português_](README.pt-BR.md) | ||
| 8 | + [_English_](README.md) | ||
| 9 | + | ||
| 10 | + En ciencias de la computaciòn una **lista enlazada** es una coleccion linear | ||
| 11 | + de elemntos de datos, en los cuales el orden linear no es dado por | ||
| 12 | + su posciòn fisica en memoria. En cambio, cada | ||
| 13 | + elemento señala al siguiente. Es una estructura de datos | ||
| 14 | + que consiste en un grupo de nodos los cuales juntos representan | ||
| 15 | + una secuencia. Bajo la forma mas simple, cada nodo es | ||
| 16 | + compuesto de datos y una referencia (en otras palabras, | ||
| 17 | + un lazo) al siguiente nodo en la secuencia. Esta estructura | ||
| 18 | + permite la insercion o remocion de elementos | ||
| 19 | + desde cualquier posicion en la secuencia durante la iteracion. | ||
| 20 | + Variantes mas complejas agregan lazos adicionales, permitiendo | ||
| 21 | + una eficiente insercion o remocion desde referencias arbitrarias | ||
| 22 | + del elemento. Una desventaja de las listas lazadas es que el tiempo de | ||
| 23 | + acceso es linear (y dificil de canalizar) Un acceso | ||
| 24 | + mas rapido, como un acceso aleatorio, no es factible. Los arreglos | ||
| 25 | + tienen una mejor locazion comparados con las listas lazadas. | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +  | ||
| 29 | + | ||
| 30 | + ## Pseudocodigo para operacones basicas | ||
| 31 | + | ||
| 32 | + ### Insertar | ||
| 33 | + | ||
| 34 | + ```text | ||
| 35 | + Add(value) | ||
| 36 | + Pre: value is the value to add to the list | ||
| 37 | + Post: value has been placed at the tail of the list | ||
| 38 | + n ← node(value) | ||
| 39 | + if head = ø | ||
| 40 | + head ← n | ||
| 41 | + tail ← n | ||
| 42 | + else | ||
| 43 | + tail.next ← n | ||
| 44 | + tail ← n | ||
| 45 | + end if | ||
| 46 | + end Add | ||
| 47 | + ``` | ||
| 48 | + | ||
| 49 | + ```text | ||
| 50 | + Prepend(value) | ||
| 51 | + Pre: value is the value to add to the list | ||
| 52 | + Post: value has been placed at the head of the list | ||
| 53 | + n ← node(value) | ||
| 54 | + n.next ← head | ||
| 55 | + head ← n | ||
| 56 | + if tail = ø | ||
| 57 | + tail ← n | ||
| 58 | + end | ||
| 59 | + end Prepend | ||
| 60 | + ``` | ||
| 61 | + | ||
| 62 | + ### Buscar | ||
| 63 | + | ||
| 64 | + ```text | ||
| 65 | + Contains(head, value) | ||
| 66 | + Pre: head is the head node in the list | ||
| 67 | + value is the value to search for | ||
| 68 | + Post: the item is either in the linked list, true; otherwise false | ||
| 69 | + n ← head | ||
| 70 | + while n != ø and n.value != value | ||
| 71 | + n ← n.next | ||
| 72 | + end while | ||
| 73 | + if n = ø | ||
| 74 | + return false | ||
| 75 | + end if | ||
| 76 | + return true | ||
| 77 | + end Contains | ||
| 78 | + ``` | ||
| 79 | + | ||
| 80 | + ### Borrar | ||
| 81 | + | ||
| 82 | + ```text | ||
| 83 | + Remove(head, value) | ||
| 84 | + Pre: head is the head node in the list | ||
| 85 | + value is the value to remove from the list | ||
| 86 | + Post: value is removed from the list, true, otherwise false | ||
| 87 | + if head = ø | ||
| 88 | + return false | ||
| 89 | + end if | ||
| 90 | + n ← head | ||
| 91 | + if n.value = value | ||
| 92 | + if head = tail | ||
| 93 | + head ← ø | ||
| 94 | + tail ← ø | ||
| 95 | + else | ||
| 96 | + head ← head.next | ||
| 97 | + end if | ||
| 98 | + return true | ||
| 99 | + end if | ||
| 100 | + while n.next != ø and n.next.value != value | ||
| 101 | + n ← n.next | ||
| 102 | + end while | ||
| 103 | + if n.next != ø | ||
| 104 | + if n.next = tail | ||
| 105 | + tail ← n | ||
| 106 | + end if | ||
| 107 | + n.next ← n.next.next | ||
| 108 | + return true | ||
| 109 | + end if | ||
| 110 | + return false | ||
| 111 | + end Remove | ||
| 112 | + ``` | ||
| 113 | + | ||
| 114 | + ### Atrevesar | ||
| 115 | + | ||
| 116 | + ```text | ||
| 117 | + Traverse(head) | ||
| 118 | + Pre: head is the head node in the list | ||
| 119 | + Post: the items in the list have been traversed | ||
| 120 | + n ← head | ||
| 121 | + while n != ø | ||
| 122 | + yield n.value | ||
| 123 | + n ← n.next | ||
| 124 | + end while | ||
| 125 | + end Traverse | ||
| 126 | + ``` | ||
| 127 | + | ||
| 128 | + ### Atravesar en Reversa | ||
| 129 | + | ||
| 130 | + ```text | ||
| 131 | + ReverseTraversal(head, tail) | ||
| 132 | + Pre: head and tail belong to the same list | ||
| 133 | + Post: the items in the list have been traversed in reverse order | ||
| 134 | + if tail != ø | ||
| 135 | + curr ← tail | ||
| 136 | + while curr != head | ||
| 137 | + prev ← head | ||
| 138 | + while prev.next != curr | ||
| 139 | + prev ← prev.next | ||
| 140 | + end while | ||
| 141 | + yield curr.value | ||
| 142 | + curr ← prev | ||
| 143 | + end while | ||
| 144 | + yield curr.value | ||
| 145 | + end if | ||
| 146 | + end ReverseTraversal | ||
| 147 | + ``` | ||
| 148 | + | ||
| 149 | + ## Complexities | ||
| 150 | + | ||
| 151 | + ### Time Complexity | ||
| 152 | + | ||
| 153 | + | Access | Search | Insertion | Deletion | | ||
| 154 | + | :-------: | :-------: | :-------: | :-------: | | ||
| 155 | + | O(n) | O(n) | O(1) | O(n) | | ||
| 156 | + | ||
| 157 | + ### Space Complexity | ||
| 158 | + | ||
| 159 | + O(n) | ||
| 160 | + | ||
| 161 | + ## References | ||
| 162 | + | ||
| 163 | + - [Wikipedia](https://en.wikipedia.org/wiki/Linked_list) | ||
| 164 | + - [YouTube](https://www.youtube.com/watch?v=njTh_OwMljA&index=2&t=1s&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments