Operation Name | Operation Type | Description | Worst Time Complexity |
---|---|---|---|
Push | Insertion | Adds item to the collection end | O(1) |
Unshift | Insertion | Adds item to the collection start | O(1) |
Pop | Deletion | Adds item to the collection end | O(1) |
Shift | Deletion | Adds item to the collection start | O(1) |
Get | Search | Search item in the collection by index | O(n) |
Set | Search/Insert | Search item in specific position and replace its value | O(n) |
Insert | Search/Insert | Search item in specific position and set item as its next value, reference old next as item`s next. | O(n) |
Remove | Search/Remove | Remove item in a specific position connection directly the two immediate neighbors. | O(n) |
It has a time complexity of O(1) because it doesn`t need to iterate trought the links.
Has a time complexty of O(1) because it can access the last item directly in order to remove the link and move the 'tail' pointer to the previous link.
Search items either by their indexes, returning their value. Has a time complexty of O(n/2) because it has to iterate each node linearly until the requested item. It can begin by head or tail wether the requested position is closer from one or other.
Search item in specific position and replace its value. Has a time complexty of O(n/2) because it has to iterate the list the same way as 'Get' method, until the requested item and then replacing the value of requested node with O(1) time complexity. Removing non dominant operation we have O(n/2).
Search item in specific position and then set as next of the previous one and set current position item as next. Has a time complexity of O(n/2) because it has to iterate each node the same way as in 'Get' method.
Remove item in a specific position connection directly the two immediate neighbors. Has a time complexity of O(n) because it has to iterate each node linearly the same way as in 'Get' method.
Invert all items in a given collection. Has a time complexity of O(n) because it has to iterate the whole collection linearly to reorder the nodes.