For really wrapping our heads around the concept of linked lists, it’s important to understand why they’re needed.

The need for linked lists:

Imagine that you are a tutor, having 4 students in your class; whose marks you have to store. On creating an array of capacity 4, you will have assigned a unique address to the collection of their marks. Now, a new student joins your class. Having to store his marks as well, you realise that you cannot extend the capacity of the previously created array; nor can you store this child’s marks separately.
This is where linked lists come in.

Working of linked lists:

The working of linked lists can be explained with yet another simple example.

You are inviting 5 friends to a party, but you know the address of only one of them. Hence, you go to this friend’s house to hand over their invitation, and ask for another friend’s address. On obtaining the address of the next friend, you have figured out a very convenient method of distributing your invitations. Also, once you reach the fifth friend’s house, you have zero invitations left.

The arrows show the link between each node in the linked list. When there are zero invitations left, there is no address; hence ‘NULL’.

This is exactly the principle of linked lists.

Instead of storing data in an array which is of permanent capacity; it is possible to store data in the form of individual nodes (pieces of data with a unique address), attaching the address of the following node with the previous one.

Visits: 62

One Reply to “Linked Lists”

Leave a Reply

Your email address will not be published. Required fields are marked *