Skip to content

Latest commit

 

History

History

SinglyLinkedList

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Singly Linked List

Worst Case Time Complexity by Operation

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(n)
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)
Remove Search/Insert Invert all items in a given collection. O(n)

Operations Complexity Description

Push:

It has a time complexity of O(1) because it doesn`t need to iterate trought the links.

Pop:

Has a time complexty of O(n) because it has to search the last item linearly in order to remove the link and move the 'tail' pointer to the previous link.

Get:

Search items either by their indexes, returning their value. Has a time complexty of O(n) because it has to iterate each node linearly beginning from head until the requested item.

Set:

Search item in specific position and replace its value. Has a time complexty of O(n) because it has to iterate each node linearly beginning from head 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).

Insert:

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) because it has to iterate each node linearly beggining from head until the requested index position.

Remove:

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 beggining from head until the requested index position.

Reverse:

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.