0% found this document useful (0 votes)
28 views16 pages

Lecture 3 Linked List DSA

A linked list is a dynamic, non-continuous data structure that allows efficient insertion and deletion of elements without the need for shifting, unlike arrays. It has advantages such as dynamic sizing and memory efficiency, but also comes with disadvantages like random access limitations and extra memory usage for pointers. There are various types of linked lists, including singly, doubly, and circular linked lists, each with its own structure and implementation details.

Uploaded by

sarimayubi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views16 pages

Lecture 3 Linked List DSA

A linked list is a dynamic, non-continuous data structure that allows efficient insertion and deletion of elements without the need for shifting, unlike arrays. It has advantages such as dynamic sizing and memory efficiency, but also comes with disadvantages like random access limitations and extra memory usage for pointers. There are various types of linked lists, including singly, doubly, and circular linked lists, each with its own structure and implementation details.

Uploaded by

sarimayubi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

DATA STRUCTURES

AND ALGORITHMS
LINKED LIST
PREVIOUSLY
• What is an Array
• Disadvantages
• Advantages
• What is 2d Array
• Exercise (Practice Question)

2
WHAT IS LINKED
LIST?
LINKED LIST
• Its collection of Data Structure
• Its dynamic (non-fixed) collection of
data
• Its dynamic (non-fixed) collection of
similar typed data
• Its non-continuous dynamic (non-
fixed) collection of similar typed data
• Its non–indexed based data structure
IT IS A NON-CONTINUOUS STREAMED
COLLECTION OF DYNAMIC SIZED & SIMILAR
TYPED DATA STRUCTURE

5
ADVANTAGES
LINKED LIST
• Dynamic Sized
• Has no size limit. During runtime, its size increases

• Non-Continuous
• Since its dynamic its not placed in memory in sequential format

• Efficient Insertion and Deletion


• Array requires shifting of elements while linked list doesn’t

• It simply adds new node between two nodes

• Memory Efficiency
• Only allocates memory as per size of linked list currently
containing values

• No empty nodes to waste memory


ADVANTAGES
LINKED LIST
• Easy Implementation of Abstract Data
Types
• Stacks and Queues are easily implemented via
abstract datatypes
• Frequent insertion and deletion of elements.
Hence, linked list is preferred for stack and
queues
• More Efficient Sorting
• Linked list is considered more suitable for
sorting algorithms as compared to array
• Does not require swapping of elements like
arrays. Efficiency factor here.
DISADVANTAGES
LINKED LIST
• Random Access
• You cannot access any element directly. You
either start from 1st node or end node if its
doubly linked list
• Extra Memory Usage
• As it contains pointer to next or previous
depending on type of linked list
• It requires more memory to store address of
previous or next element
• More Complex Implementation
• Due to managing pointers to next and previous
nodes
TIME COMPLEXITY

9
TYPES
SINGLY LINKED LIST​
• Each node points to the next node in the linked list.

• Each node has pointer to next node

10
TYPES
DOUBLY LINKED LIST​
• Each node points to the next and previous node in the
linked list.

• A pointer to next node


• A pointer to previous node

11
TYPES
CIRCULAR LINKED LIST​
• Each node points to the next and previous node in the
linked list.

• A Circular singly linked list has a pointer to next node and


last node points to first node
• A Circular doubly linked list has a pointer to next node and
previous node. Its last node points to first node

12
IMPLEMENTATION
LINKED LIST
class Node {
int data; // Data part of the node
Node next; // Pointer to the next node
//Node is abstract type here

// Constructor to create a new node


Node(int data) {
this.data = data;
this.next = null;
// Initialize next to null as it is a single node
}

// Function to display the node data


void display() {
System.out.println("Node data: " + data);
}
}
IMPLEMENTATION
LINKED LIST - CONTINUED
public class LinkedList {
public static void main(String[] args) {
// Creating a single node with data 10
Node singleNode = new Node(10);

// Display the node's data


singleNode.display();
}
}
IMPLEMENTATION
LINKED LIST – 2ND NODE
// Creating the first node with data 10
Node firstNode = new Node(10);

// Creating the second node with data 20


Node secondNode = new Node(20);

// Linking the first node to the second node


firstNode.next = secondNode;
THANK YOU

16

You might also like