Linked List Basic Demonstration Presentation.pptx

sajiaph 6 views 29 slides Mar 02, 2025
Slide 1
Slide 1 of 29
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29

About This Presentation

Introduction
Array vs Linked List
Node Structure
Types of Linked List
Basic operations
Traversal in a Linked List
Insertion in a Linked List
Real Life applications and Shortcomings


Slide Content

Linked List Prepared by SAJIA BINTEA JAHANGIR

OUTLINE Introduction Array vs Linked List Node Structure Types of Linked List Basic operations Traversal in a Linked List Insertion in a Linked List Real Life applications and Shortcomings

LINKED LIST What is a Linked List? A Linked List is a linear data structure to store data where each item points to the next one. Each item is called a node . A node has: Data (the value). Pointer (points to the next node).

ARRAY VS LINKED LIST ARRAY LINKED LIST Array Linked List Fixed size; needs predefined capacity Dynamic size; grows as needed Direct access via index Sequential access; must traverse nodes For insertion/deletion shifting required No shifting, just pointer adjustment Less memory (no extra pointers) More memory (extra pointer per node)

NODE STRUCTURE A node structure is the basic building block of a linked list.

NEW NODE CREATION How to create a new node? Allocate Memory Set Data Value Set Next pointer to Null Return New Node

C++ IMPLEMENTATION OF CREATE NODE

TYPES OF LINKED LIST 3 types Single Linked List Doubly Linked List Circular Linked List

SINGLE LINKED LIST A Single Linked List is a linear data structure where each node points to the next node, and the last node points to NULL , marking the end of the list.

DOUBLY LINKED LIST A Doubly Linked List is a linear data structure where each node contains links to both the next node and the previous node, allowing traversal in both directions (forward and backward).

CIRCULAR LINKED LIST A linked list where the last node points back to the first node, forming a circle.

BASIC OPERATIONS 3 basic operations Traversal Insertion Deletion

TRAVERSAL IN A LINKED LIST Visiting each node in the linked list to access or process the data stored in the nodes. Start at the head and follow the links until the end of the list.

STEPS OF TRAVERSAL Steps for Traversing a Linked List Start from the head node.​ Visit the data in the current node.​ Move to the next node . Repeat steps 2 and 3 until  the next node is NULL.

PSEUDOCODE FOR TRAVERSAL function traverse(head):  temp = head  while temp is not NULL:  print temp.data temp = temp.next

C++ IMPLEMENTATION OF TRAVERSAL

INSERTION IN A LINKED LIST There are three possible places to insert a node in a linked list: At the beginning . At the end . In the middle , after a given node.

INSERTION AT THE BEGINING Steps for inserting a node at the beginning Create a new node. Make the new node point to the current head. Update the head to the new node.

DIAGRAM FOR INSERTING AT THE BEGINING

C++ IMPLEMENTARION

INSERTION AT THE END Steps for inserting a node at the beginning Create a new node. Traverse the list to find the last node. Make the last node's next point to the new node.

DIAGRAM FOR INSERTING AT THE END

C++ IMPLEMENTARION

INSERTION IN THE MIDDLE Steps: Create a new node. Make the new node's next point to the given node's next . Make the given node's next point to the new node.

DIAGRAM FOR INSERTING IN THE MIDDLE

C++ IMPLEMENTARION

REAL LIFE APPLICATION OF LINKED LIST Used in memory management to allocate and free memory blocks dynamically. Implement data structures like queues and stacks . Help in creating playlists where you can navigate to the next or previous song. Previous and next page in a web browser.

SHORTCOMINGS OF LINKED LIST More memory : Extra pointer in each node. Slower traversal : No direct access by index. No random access : Must traverse sequentially.

THANK YOU for your patience.