Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 1.58 KB

File metadata and controls

48 lines (39 loc) · 1.58 KB

LinkedList

A linked list is a data structure that consists of a group of nodes where each node contains a data value and a reference (or link) to the next node in the list.

Example

let list = [4,3,1,0,14,6];
Memory Location Value
1000 4
1001 1008
1002 1
1003 1004
1004 0
1005 1006
1006 14
1007 1010
1008 3
1009 1002
1010 6
1011 1000

Accessing an element in a linked list is done by traversing the list and finding the element at the correct index.

index 0 value is 4 with memory location 1000 and pointer to next node 1008
index 1 value is 3 with memory location 1008 and pointer to next node 1002
index 2 value is 1 with memory location 1002 and pointer to next node 1004
index 3 value is 0 with memory location 1004 and pointer to next node 1006
index 4 value is 14 with memory location 1006 and pointer to next node 1010
index 5 value is 6 with memory location 1010 and pointer to first node 1000

Linked List Image

Time complexities of some basic Linked List operations

Operation Time Complexity
Accesing an element O(N)
Searching an element O(N)
Inserting an element O(1)
Deleting an element O(1)