0% found this document useful (0 votes)
30 views24 pages

3.2 Linked Lists Types

Uploaded by

Sana Khan
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)
30 views24 pages

3.2 Linked Lists Types

Uploaded by

Sana Khan
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
You are on page 1/ 24

Data Structure and

Algorithm (IT-209)
Instructor: Abdullah Javed
([email protected])
Lecturer,
Govt. Postgraduate College, Jhelum

Lecture 3.2
Fall 2020
Agenda
• Linked List Variants
 Singly
 Doubly
 Circular
 Doubly Circular

2
Variations of Linked Lists
• The linked list that we studied so far is called singly
linked list
• Other types of linked lists exist, namely:
– Circular linked linked list
– Doubly linked list
– Circular doubly linked list

• Each type of linked list may be suitable for a


different kind of application
• They may also use a dummy head for simplifying
insertions and deletions
3
Singly Linked List
• Advantages
 Dynamic allocation
 Efficient Insertion and Deletion

• Disadvantages
 Each node maintain forward linkage only
 Overhead
 Insertion & deletion at end - Reach Predecessor
 Within sight
 But, out of reach
 Expensive operation
 Depends upon the length of the list

4
Doubly Linked List
• Each node maintain two pointer
 One pointing forward
 One pointing backward

5
Doubly Linked List

6
Doubly Linked Lists
pHead

a b c

Advantages:
• Convenient to traverse the list backwards.
• E.g. printing the contents of the list in backward order
Disadvantage:
• Increase in space requirements due to storing two pointers
instead of one

7
Doubly Linked List Operations
• Insert a node At the start of the list
 In the middle of the list
 At the end of the list

• Deletion a node At the start of the list


 In the middle of the list
 At the end of the list

• Traversal
 At the start of the list
 At the end of the list

• Searching
 Scan list contents

8
Insert at Start

9
Insert at Start

10
Insert at Start

11
Insert at End

12
Insert at End

13
Insert at End

14
Delete from Start

15
Delete from Start

16
Delete from End

17
Delete from End

18
Traversal
• Scan list
 Starting from the start of the list, moving one node forward
 Starting from the end of the list, moving one node backward

• Traversal from Start: Traversal from End:

19
Searching

20
current
Home Task

• At the middle
 Insert an item
 Delete an item
newNode

oldNode

21
Circular Linked Lists
• Last node references the first node
• Every node has a successor
• No node in a circular linked list contains NULL
• E.g. a turn-based game may use a circular linked list to switch
between players
• Application
 Fair distribution of resources among processes

• Usage
 Move current pointer ahead to activate next process

22
Circular Doubly Linked Lists
• Circular doubly linked list
– prev pointer of the dummy head node points to the last node
– next reference of the last node points to the dummy head node
– No special cases for insertions and deletions

(a) A circular doubly linked list with a dummy head node


(b) An empty list with a dummy head node
23
Arrays of Linked List
• Interesting structure that combines static with
dynamic structure
• Array of head pointers
• Application
 A job portal website maintain categories
and one member falls only in one category
 Where
 Each category – index of array
 Member within category – item of linked list

24

You might also like