Python Data Structures - Linked List - Part 1

 


Linked List:

A linked list is a form of a collection of data.

Data does not have to be in any order.

A linked list comprises independent nodes (data + links).

Each node contains a link to the next node in the link.

Imagine a linked list of a train car.



How the linked list is different from the list/array?

1) List/Array uses the index to fetch the elements.
2) List/Array stores the element in a continuous memory location.


Below is the linked list.



Type of linked list:

Single linked list:

Each node holds data and references to the next node in the list. Reference is the memory location/address of the node.

Node 1 holds the address of Node 2 and it goes on until the tail of the linked list.

This type of linked list provides the ability to add and remove nodes in run time.

Circular linked list:

Reference of the last node points to the address of the first node in the linked list and it creates a circle.

This is used in multiple-player games.



Circular double linked list:

It’s a combination of circular and double linked list. Each node has the reference to the first and next node in the list. Last node in the list points to the first node in the list.







Comments

Popular posts from this blog

SRE/DevOps Syllabus

AWS Code Commit - CI/CD Series Part 1

Docker - Preventing IP overlapping