Understanding basic operations through illustrations

Today we will see a linked list

Say we stored ‘RONALDO’ in a Linked List

Linked List storing ‘RONALDO’

Insertion at first which means we missed ‘R’ in ‘RONALDO’

‘R’ inserted at the start

Notice we just changed the pointer link of ‘R’ to ‘O’ address

There are no further operations like shifting all the elements to the right because of no indexing for ‘Linked Lists’.

Insertion at the middle which means we missed ‘A’ in ‘RONALDO’.

‘A’ inserted in the middle

Notice only link or pointer changes to different memory locations. That too previous and next link.

Inserting at last position — Missing ‘O’ in RONALDO

Inserting ‘O’ at the last position

Since ‘O’ is the last element, we made ‘D’ pointing to ‘O’ and ‘O’ pointing to ‘null’

The same is the case with the ‘Deletion’ operation but opposite.

No matter where the insertion or deletion is(i.e First, middle or last), the Linked list concerns only the previous and next link.

Therefore time consumed for this operation is less and constant and it is always the best-case scenario.

Therefore for Insertion and deletion operations, linked lists serves best

--

--

Arjun Vaidy

Founder of a startup. I explain things through first principles and intuitive mental models