You are on page 1of 20

Linked List

Contents
 Introduction
 Why Linked Lists?
 Linked vs Arrays
 Variations of Linked Lists
 Basic Operations
 Programs
Introduction

 Linked list is a commonly used dynamic linear data


structure which consists of group of nodes in a
sequence. Each node consists of data and reference
to other nodes forming a chain like structure. The
first node is usually called the head node.
Why Linked Lists?

 Limitations of Arrays
 The size of array is fixed i.e. static structure.
 Significant amount of memory is wasted when
speculating the upper limit on the number of elements
in advance.
 Inserting or deleting in array of elements is expensive
as memory has to be arranged for the new elements and
then the shifting is done.
Linked Lists vs Arrays
 Non-primitive data  Primitive data structure.
structure.  Static memory allocation.
 Dynamic memory  Random access.
allocation.  Continous memory
 Sequential access. allocation.

 Memory can be  Arrays have better cache


locality.
allocated anywhere in
the memory.
Variations of Linked Lists
struct node
{
T data;
struct node *next;
}

Singly Linked List


struct node
{
T data;
struct node *next;
struct node *prev;
}
Doubly Linked List
struct node
{
T data;
struct node *next;
}

Circular Linked List


Basic Operations

 Creation
 Insertion
 Deletion
 Traverse
 Search
 Reverse
 Length
Programs
 Insertion at head
Programs
 Insertion at tail
Programs
 Insert at specific position
Programs
 Delete at specified position
Programs
 Delete all occurences
 of node with given key
Programs
 Reverse a linked list
Programs
 Merge two sorted linked lists
Programs
 Cycle detection or Loop detection
Programs
 Find intersection point or merging point
Programs
 Find middle element of the list
Programs
 Swap nodes without swapping the data
Programs
 Add two numbers repesented as linked lists
Programs
 Delete duplicate node values
 Is linked list a palindrome?
 Sort linked list sorted on absolute values
 Insert in sorted manner
 Subtract two numbers represented as linked lists
 Flatten a multilevel linked list
 Delete N nodes after M nodes
 Convert Binary tree to Circular Doubly Linked List
 Quick Sort and Merge Sort on Linked lists

You might also like