Translated to portuguese (#330)

This commit is contained in:
Nilton Lopes 2019-03-22 02:25:48 -03:00 committed by Oleksii Trekhleb
parent 38d0ccc222
commit c510775f39

View File

@ -0,0 +1,155 @@
# Linked List
_Leia em outros idiomas:_
[_简体中文_](README.zh-CN.md),
[_Русский_](README.ru-RU.md)
[_Português_](README.pt-BR.md)
Em ciência da computação, uma **lista ligada** é uma coleção linear
de elementos de dados, em que a ordem linear não é fornecida pelo seu
posicionamento físico na memória. Em vez disso, cada elemento aponta para o próximo.
É uma estrutura de dados consistente de um grupo de nós que juntos
representam uma sequência. De forma simples, cada nó é composto de dado
e uma referência (em outras palavras, um link) para o próximo nó na sequência.
Essa estrutura permite uma inserção eficiente ou uma remoção de elementos
apartir de qualquer posição na sequência durante a iteração. Variantes
mais complexas adicionam links adicionais, permitindo inserção eficiente ou remoção
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.
![Linked List](https://upload.wikimedia.org/wikipedia/commons/6/6d/Singly-linked-list.svg)
## Pseudo código para Operações Básicas
### Inserção
```text
Add(value)
Pre: value is the value to add to the list
Post: value has been placed at the tail of the list
n ← node(value)
if head = ø
head ← n
tail ← n
else
tail.next ← n
tail ← n
end if
end Add
```
```text
Prepend(value)
Pre: value is the value to add to the list
Post: value has been placed at the head of the list
n ← node(value)
n.next ← head
head ← n
if tail = ø
tail ← n
end
end Prepend
```
### Busca
```text
Contains(head, value)
Pre: head is the head node in the list
value is the value to search for
Post: the item is either in the linked list, true; otherwise false
n ← head
while n != ø and n.value != value
n ← n.next
end while
if n = ø
return false
end if
return true
end Contains
```
### Deleção
```text
Remove(head, value)
Pre: head is the head node in the list
value is the value to remove from the list
Post: value is removed from the list, true, otherwise false
if head = ø
return false
end if
n ← head
if n.value = value
if head = tail
head ← ø
tail ← ø
else
head ← head.next
end if
return true
end if
while n.next != ø and n.next.value != value
n ← n.next
end while
if n.next != ø
if n.next = tail
tail ← n
end if
n.next ← n.next.next
return true
end if
return false
end Remove
```
### Traverse
```text
Traverse(head)
Pre: head is the head node in the list
Post: the items in the list have been traversed
n ← head
while n != ø
yield n.value
n ← n.next
end while
end Traverse
```
### Traverse in Reverse
```text
ReverseTraversal(head, tail)
Pre: head and tail belong to the same list
Post: the items in the list have been traversed in reverse order
if tail != ø
curr ← tail
while curr != head
prev ← head
while prev.next != curr
prev ← prev.next
end while
yield curr.value
curr ← prev
end while
yield curr.value
end if
end ReverseTraversal
```
## Complexidades
### Tempo de complexidade
| Access | Search | Insertion | Deletion |
| :----: | :----: | :-------: | :------: |
| O(n) | O(n) | O(1) | O(n) |
### Spaço de complexidade
O(n)
## Referências
- [Wikipedia](https://en.wikipedia.org/wiki/Linked_list)
- [YouTube](https://www.youtube.com/watch?v=njTh_OwMljA&index=2&t=1s&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)