Singly Linked Lists
Understand what is Singly Linked Lists.
What is Linked lists?
Linked list stores elements in an ordered sequence. They are made up of a lists of nodes called (ListNode) This ListNode object contains two attributes:
- value - The node value (exp: character, integer, object, etc)
- next - It's actually a pointer that stores the reference to the next node in the linked list.
Array are stored the same way in memory but linked list does not necessarily to store the same way in memory like array.
Head is the 1st node, while Tail is the last node. Make sure you adjust Head/Tail node when appending a new node or removing the node.
Operation | Big-O Time | Notes |
---|---|---|
Access | O(n) | Have to loop to find the exact |
Search | O(n) | - |
Insert | O(1) | Reference to the node (position) |
Delete | O(1) | Reference to the node (position) |