Skip to content

Commit c510775

Browse files
nillswetrekhleb
authored andcommittedMar 22, 2019
Translated to portuguese (#330)
1 parent 38d0ccc commit c510775

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Linked List
2+
3+
_Leia em outros idiomas:_
4+
[_简体中文_](README.zh-CN.md),
5+
[_Русский_](README.ru-RU.md)
6+
[_Português_](README.pt-BR.md)
7+
8+
Em ciência da computação, uma **lista ligada** é uma coleção linear
9+
de elementos de dados, em que a ordem linear não é fornecida pelo seu
10+
posicionamento físico na memória. Em vez disso, cada elemento aponta para o próximo.
11+
É uma estrutura de dados consistente de um grupo de nós que juntos
12+
representam uma sequência. De forma simples, cada nó é composto de dado
13+
e uma referência (em outras palavras, um link) para o próximo nó na sequência.
14+
Essa estrutura permite uma inserção eficiente ou uma remoção de elementos
15+
apartir de qualquer posição na sequência durante a iteração. Variantes
16+
mais complexas adicionam links adicionais, permitindo inserção eficiente ou remoção
17+
arbitrária de referências do elemento. Uma desvantagem da lista ligada é que o tempo de acesso é linear (e dificulta para pipeline) Acesso rápido, assim como acesso randômico, não é viável. Arrays têm um melhor cache de localidade quando comparado com listas ligadas.
18+
19+
![Linked List](https://upload.wikimedia.org/wikipedia/commons/6/6d/Singly-linked-list.svg)
20+
21+
## Pseudo código para Operações Básicas
22+
23+
### Inserção
24+
25+
```text
26+
Add(value)
27+
Pre: value is the value to add to the list
28+
Post: value has been placed at the tail of the list
29+
n ← node(value)
30+
if head = ø
31+
head ← n
32+
tail ← n
33+
else
34+
tail.next ← n
35+
tail ← n
36+
end if
37+
end Add
38+
```
39+
40+
```text
41+
Prepend(value)
42+
Pre: value is the value to add to the list
43+
Post: value has been placed at the head of the list
44+
n ← node(value)
45+
n.next ← head
46+
head ← n
47+
if tail = ø
48+
tail ← n
49+
end
50+
end Prepend
51+
```
52+
53+
### Busca
54+
55+
```text
56+
Contains(head, value)
57+
Pre: head is the head node in the list
58+
value is the value to search for
59+
Post: the item is either in the linked list, true; otherwise false
60+
n ← head
61+
while n != ø and n.value != value
62+
n ← n.next
63+
end while
64+
if n = ø
65+
return false
66+
end if
67+
return true
68+
end Contains
69+
```
70+
71+
### Deleção
72+
73+
```text
74+
Remove(head, value)
75+
Pre: head is the head node in the list
76+
value is the value to remove from the list
77+
Post: value is removed from the list, true, otherwise false
78+
if head = ø
79+
return false
80+
end if
81+
n ← head
82+
if n.value = value
83+
if head = tail
84+
head ← ø
85+
tail ← ø
86+
else
87+
head ← head.next
88+
end if
89+
return true
90+
end if
91+
while n.next != ø and n.next.value != value
92+
n ← n.next
93+
end while
94+
if n.next != ø
95+
if n.next = tail
96+
tail ← n
97+
end if
98+
n.next ← n.next.next
99+
return true
100+
end if
101+
return false
102+
end Remove
103+
```
104+
105+
### Traverse
106+
107+
```text
108+
Traverse(head)
109+
Pre: head is the head node in the list
110+
Post: the items in the list have been traversed
111+
n ← head
112+
while n != ø
113+
yield n.value
114+
n ← n.next
115+
end while
116+
end Traverse
117+
```
118+
119+
### Traverse in Reverse
120+
121+
```text
122+
ReverseTraversal(head, tail)
123+
Pre: head and tail belong to the same list
124+
Post: the items in the list have been traversed in reverse order
125+
if tail != ø
126+
curr ← tail
127+
while curr != head
128+
prev ← head
129+
while prev.next != curr
130+
prev ← prev.next
131+
end while
132+
yield curr.value
133+
curr ← prev
134+
end while
135+
yield curr.value
136+
end if
137+
end ReverseTraversal
138+
```
139+
140+
## Complexidades
141+
142+
### Tempo de complexidade
143+
144+
| Access | Search | Insertion | Deletion |
145+
| :----: | :----: | :-------: | :------: |
146+
| O(n) | O(n) | O(1) | O(n) |
147+
148+
### Spaço de complexidade
149+
150+
O(n)
151+
152+
## Referências
153+
154+
- [Wikipedia](https://en.wikipedia.org/wiki/Linked_list)
155+
- [YouTube](https://www.youtube.com/watch?v=njTh_OwMljA&index=2&t=1s&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)

0 commit comments

Comments
 (0)
Please sign in to comment.