Friday, February 21, 2020

Linked List In Python

Linked List In Python

A linked list is a simple data structure composed of nodes in sequence. The node is formed of an element(item) and a reference(link). The chain of nodes is created by putting them together into a sequence using their references. Complex data structures like lists, stacks, queues, and associative arrays can be built with the help of Linked Lists. The Linked List is a dynamic data structure, it means we can apply several operations like add, update, delete, insert, modify, etc on a Linked List at runtime. Generally, Linked Lists provides efficient insertion and deletion operations.
Linked List Python
A Simple Linked List

Basically, a Linked List is a dynamic data structure and collection of nodes connected to each other in linear order, making the linear traversal easy and possible. Each node carries an element(item/data) and reference to the node following it. The first node is known as Head, it does not carry any data, but just contains the link to the first node. The last node refers to null. Python does not provide built-in Linked List implementation. 

Advantages of the basic linked lists are

  1. Dynamic data structure
  2. Easy insertion and deletion process

Disadvantages of the basic Linked Lists are

  1. No Random-access like simple arrays
  2. Extra memory consumption as the link is also carried by the node along with data
  3. No cache-friendly as the node is not stored at contiguous memory locations

Linked List Example