SlideShare a Scribd company logo
DOUBLY LINKED LIST
CREATED BY:
1507011- TAHMINA RAHMAN
1507012- SAMIUL AZIM
1507013- FABLIHA HAQUE
1507014- SALIM SHADMAN ANKUR
1507015- SAIFUR RAHMAN
TOPICS:
โ€ข linked lists
โ€ข doubly linked list
โ€ข Creation and traversing of doubly linked list
โ€ข Insertion and deletion on doubly linked list
โ€ข complexity of insertion and deletion
โ€ข Advantages and disadvantages of doubly linked list
LINKED LIST
๏ƒ˜ Like arrays, Linked List is a linear data structure
๏ƒ˜ Unlike arrays, linked list elements are not stored at contiguous
location
๏ƒ˜ the elements are linked using pointers
๏ƒ˜ does not have any index
ADDRESSES FOR LINKED LIST AND ARRAY
Linked List Arrray
WHY WE USE LINKED LIST
Arrays can be used to store linear data of similar
types, but arrays have following limitations..
1) The size of the arrays is fixed .
2) Inserting a new element in an array of elements is expensive, because room
has to be created for the new elements and to create room existing elements
have to shifted.
DOUBLY LINKED LIST
โ€ข A Doubly Linked List (DLL) contains an extra pointer, typically called previous
pointer, together with next pointer and data which are there in singly linked
list.
โ€ข Every nodes in the doubly linked list has three fields:
1. Left Pointer (prev)
2. Right Pointer (next)
3. Data (info)
DOUBLY LINKED LIST
โ€ข Prev - address of the previous node
โ€ข Next - address of the next node
โ€ข Info - information of the node
โ€ข head - address of the first node
Prev Info Next
node
CREATION OF DOUBLY LINKED LIST
Steps-
1: Head := NULL (as global)
2: New Node (Ptr)
// set data and prev , next to NULL
3: If Head = NULL
๏ƒ˜ Head := ptr
๏ƒ˜ temp := ptr
4. If not
๏ƒ˜ temp โ†’ next := ptr
๏ƒ˜ Ptr โ†’ prev := temp
๏ƒ˜ temp := ptr
CREATION OF DOUBLY LINKED LIST
NULL data1 NULL
0x80
0x80 data2 NULLNULL data1 0x81
0x810x80
0x80 data2 0x81NULL data1 0x81 0x81 data3 NULL
0x80 0x81 0x82
No element inserted
Third element inserted:
Second element inserted:
First element inserted:
Empty list
Head
temp
Head
temp
Head
temp
TRAVERSING
0x80 9 0x82NULL 8 0x81 0x81 10 NULL
Head Srt
Steps:
Set srt := head
while ( srt->next != NULL)
print srt->info // 8
srt := srt->next
if (srt->next == NULL)
print srt->info
end of traversing
0x80 0x81 0x82
False
Not Executed
Output:
8
Srt
0x80
0x81
Srt
TRAVERSING
0x80 9 0x82NULL 8 0x81 0x81 10 NULL
Head Srt
Steps:
Set srt := head
while ( srt->next != NULL)
print srt->info // 9
srt := srt->next
if (srt->next = NULL)
print srt->info
end of traversing
0x80 0x81 0x82
True
Output:
8
9
10
Srt
0x80
0x81
0x82
Srt
OPERATIONS ON DOUBLY LINKED LIST
Insertion
โ€ข Insert an element at first
โ€ข Insert an element at last
โ€ข Insert before a given element
โ€ข Insert after a given element
Deletion
โ€ข Delete first element
โ€ข Delete last element
โ€ข Delete a given element
โ€ข Delete before a given element
โ€ข Delete after a given element
INSERT AN ELEMENT AT FIRST
prev info NULLprev info nextNULL info next
Head
Steps-
1. New node (Ptr)
prev info next
Ptr
INSERT AN ELEMENT AT FIRST
prev info NULLprev info nextinfo next
Head
data
Steps-
1. New node (Ptr)
2. Ptr โ†’ info := data
3. Ptr โ†’ prev := NULL
4. Ptr โ†’ next := NULL
Ptr
NULL
NULL
NULL
INSERT AN ELEMENT AT FIRST
prev info NULLprev info nextinfo next
Head
NULL data
Steps-
1. New node (Ptr)
2. Ptr โ†’ Info := data
3. Ptr โ†’ prev := NULL
4. Ptr โ†’ next := NULL
5. Head โ†’ prev := ptr
6. Ptr โ†’ next := head
7. Head := Ptr
Ptr
NULL
NULL
Head
EXAMPLE OF FIRST INSERTION:
This is a doubly linked list โ€ฆ.
0x81 8 XX 1 0x81 0x80 5 0x82
Inserting 45 at the first of the list
0x820x810x80
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 45 X
0x90
0X900X80
INSERT AN ELEMENT AT LAST
prev info NULLprev info nextNULL info next
prev info next
srt
Ptr
Steps-
1. New node (Ptr)
Head
INSERT AN ELEMENT AT LAST
prev info NULLprev info nextNULL info next
info data next
srt
Ptr
Steps-
1. New node (Ptr)
2. Ptr โ†’ Info := data
Head
INSERT AN ELEMENT AT LAST
prev infoprev info nextNULL info next
data
srt
Ptr
Steps-
1. New node (Ptr)
2. Ptr โ†’ Info := data
3. Ptr โ†’ prev := NULL
4. Ptr โ†’ next := NULL
5. srt โ†’ next := ptr
6. Ptr โ†’ prev := srt
NULL NULL
NULL
Head
EXAMPLE OF LAST INSERTION:
This is a doubly linked list โ€ฆ. Insert 45 at the last of the list
0x81 8 XX 1 0x81 0x80 5 0x82
After insertion 45 at lastโ€ฆ.
0x820x810x80
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 45 X
0x90
0X820X90
INSERT BEFORE A GIVEN ELEMENT
prev info NULLprev info nextprev info next
Steps-
1. New Node(Ptr)
2. ptr โ†’info = data
NULL info next
data
given element
Ptr
srttemp
Head
INSERT BEFORE A GIVEN ELEMENT
prev info NULLprev info nextinfo next
Steps-
1. New Node(Ptr)
2. ptr โ†’info = data
3. srt โ†’prev := Ptr
4. temp โ†’next := Ptr
5. ptr โ†’prev := temp
6. ptr โ†’next := srt
NULL info
data
given element
Ptr
srttemp
next prev
Head
EXAMPLE INSERT BEFORE A GIVEN ELEMENT:
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 36 X
0x90
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
0x90
Inserting 36 before 5โ€ฆ
EXAMPLE INSERT BEFORE A GIVEN ELEMENT:
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 36 X
0x90
0x81 8 XX 1 0x80 5 0x82
0x820x810x80
0x90
Inserting 36 before 5โ€ฆ
0x90
EXAMPLE INSERT BEFORE A GIVEN ELEMENT:
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 36 X
0x90
0x81 8 XX 1 5 0x82
0x820x810x80
0x90
Inserting 36 before 5โ€ฆ
0x90 0x90
0X80 0X81
SPECIAL CASE: (IF GIVEN ELEMENT IS THE FIRST NODE
OF THE LIST)
prev info NULLprev info nextprev info nextNULL info next
Given element
๏ถ When Head โ†’info = given
element
๏ƒ˜ In this case it is similar to first
insertion โ€ฆ.
Head
INSERT AFTER A GIVEN ELEMENT
prev info NULLprev info nextprev info nextNULL info next
data
given element
srt
Head
Steps-
1. New Node (Ptr)
2. Ptr โ†’ info := data
Ptr
INSERT AFTER A GIVEN ELEMENT
prev info NULLinfo nextprev infoNULL info next
data
given element
srt
Head
Steps-
1. New Node (Ptr)
2. Ptr โ†’ info := data
3. Ptr โ†’ prev := srt
4. Ptr โ†’ next := srt โ†’ next
5. srt โ†’ next โ†’prev := Ptr
6. srt โ†’ next := Ptr
Ptr
next prev
EXAMPLE INSERT AFTER A GIVEN ELEMENT:
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 10 X
0x90
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
Inserting 10 after 5โ€ฆ
0X820X81
EXAMPLE INSERT AFTER A GIVEN ELEMENT:
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 10 X
0x90
0x81 8 XX 1 0x81 0x80 5
0x820x810x80
Inserting 10 after 5โ€ฆ
0X820X81
0x90
EXAMPLE INSERT AFTER A GIVEN ELEMENT:
0x81 8 XX 1 0x81 0x80 5 0x82
0x820x810x80
X 10 X
0x90
8 XX 1 0x81 0x80 5
0x820x810x80
Inserting 10 after 5โ€ฆ
0X820X81
0x90 0x90
SPECIAL CASE: (IF GIVEN ELEMENT IS THE LAST NODE
OF THE LIST)
prev info NULLprev info nextprev info nextNULL info next
Given element
๏ถ When srt โ†’ next = NULL
๏ƒ˜ In this case it is similar to last
insertion โ€ฆ.
Head
srt
Now Itโ€™s Time for Deletion
DELETE AN ELEMENT AT FIRST
Prev Info NextPrev Info NextNULL Info Next Prev Info NULL
Steps-
1. Set head := head->next
2. Set head->prev := NULL
Head
Head
DELETE AN ELEMENT AT FIRST
Prev Info NextInfo NextNULL Info Next Prev Info NULL
Steps-
1. Set head := head->next
2. Set head->prev := NULL
Head
NULL
EXAMPLE OF FIRST DELETION:
This is a doubly linked list โ€ฆ. Delete the first node..
0x820x810x80
0x81 8 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL
0x83
Head Head
EXAMPLE OF FIRST DELETION:
After deleting first node
0x820x81
0x81 8 0x83NULL 1 0x81 5 0x82 0x82 45 NULL
0x83
Head
NULL
0x80
DELETE AN ELEMENT AT LAST
Prev Info NextPrev Info NextNULL Info Next Prev Info NULL
Steps-
When srt->next := NULL
1. Set temp->next := NULL
Head
Temp Srt
DELETE AN ELEMENT AT LAST
Prev InfoPrev Info NextNULL Info Next Prev Info NULL
Steps-
When srt->next := NULL
1. Set temp->next := NULL
Head
Temp Srt
NULL
EXAMPLE OF LAST DELETION:
This is a doubly linked list โ€ฆ. Delete the last node..
0x820x810x80
0x81 8 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL
0x83
Head Temp Srt
EXAMPLE OF LAST DELETION:
This is a doubly linked list โ€ฆ. Delete the last node..
0x820x810x80
0x81 8NULL 1 0x81 0x80 5 0x82 0x82 45 NULL
0x83
Head Temp Srt
NULL
DELETE A NODE OF GIVEN ELEMENT
Prev Info NextPrev info NextNULL Info Next Prev Info NULL
Head
Steps-
when srt->info := item
srt->next->prev := srt->prev
srt->prev->next := srt->next
Srt
EXAMPLE OF DELETION OF A GIVEN ELEMENT:
This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 8
0x820x810x80
0x81 5 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL
0x83
8
Head Srt
EXAMPLE OF DELETION OF A GIVEN ELEMENT:
This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 8
0x820x810x80
0x80 5 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL
0x83
8
Head Srt
EXAMPLE OF DELETION OF A GIVEN ELEMENT:
After deleting the particular node
0x820x810x80
0x80 5 0x83NULL 1 0x80 5 0x82 0x82 45 NULL
0x83
8
Head
0x82
Srt
SPECIAL CASES: FOR DELETION OF GIVEN ELEMENT
I) If the given element is in the first node, it will be as same as first
element delete.
II) If the given element is in the last node, it will be as same as last
element delete.
DELETE A NODE AFTER GIVEN ELEMENT
Prev Info NextPrev Info NextNULL Info Next Prev Info NULL
Steps-
when srt->info := item
Set srt->next->next->prev := srt
srt->next=srt->next->next
Head Srt
EXAMPLE OF DELETION AFTER A GIVEN ELEMENT:
This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 1
0x820x810x80
0x81 8 0x83NULL 0x81 0x80 5 0x82 0x82 45 NULL
0x83
Head
1
Srt
EXAMPLE OF DELETION AFTER A GIVEN ELEMENT:
This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 1
0x820x810x80
0x80 8 0x83NULL 0x81 0x80 5 0x82 0x82 45 NULL
0x83
Head
1
Srt
EXAMPLE OF DELETION AFTER A GIVEN ELEMENT:
Deleting the particular node after the given element
0x820x810x80
0x80 8 0x83NULL 0x80 5 0x82 0x82 45 NULL
0x83
Head
0x821
Srt
SPECIAL CASES: FOR DELETION AFTER GIVEN ELEMENT
I) If the given element is before the last node , it will be as same as last element
delete.
II) If the given element is in the last node, it will not be possible. As the
next of last node is NULL , it will not delete anything
DELETE A NODE BEFORE GIVEN ELEMENT
Prev Info NextPrev Info NextNULL Info Next Prev Info NULL
Steps-
when srt->info := item
Set srt->prev->prev->next := srt
srt->prev:= srt-> prev->prev
Head Srt
EXAMPLE OF DELETION BEFORE A GIVEN ELEMENT:
This is a doubly linked list โ€ฆ. Delete the particular node before a given item.. Suppose the item is 9
0x820x810x80
0x81 8 0x83NULL 1 0x81 0x80 5 0x82 0x82 NULL
0x83
Head
9
Srt
EXAMPLE OF DELETION BEFORE A GIVEN ELEMENT:
This is a doubly linked list โ€ฆ. Delete the particular node before a given item.. Suppose the item is 9
0x820x810x80
0x81 8 0x83NULL 1 0x81 0x80 5 0x83 0x82 NULL
0x83
Head
9
Srt
EXAMPLE OF DELETION BEFORE A GIVEN ELEMENT:
After Deleting The Node Before A Given Element
0x820x810x80
0x81 8 0x83NULL 1 0x81 0x80 5 0x83 NULL
0x83
Head
90x81
Srt
SPECIAL CASES: FOR DELETION AFTER GIVEN ELEMENT
I) If the given element is after the first node , it will be as same as first element
delete.
II) If the given element is in the first node, it will not be possible. As the
next of first node is NULL , it will not delete anything
COMPLEXITY โ€“ FIRST / LAST INSERTION
prev info NULLprev info nextNULL info next
Head
First insertion
Last insertion
Last
COMPLEXITY โ€“ INSERTION
prev info NULLprev info nextNULL info next
Head
insertion
Last
COMPLEXITY โ€“ FIRST / LAST DELETION
prev info NULLprev info nextNULL info next
Head
First deletion
Last deletion
Last
COMPLEXITY โ€“ DELETION
prev info NULLprev info nextNULL info next
Head
deletion
Last
COMPLEXITY OF DOUBLY LINKED LIST
โ€ข Inserting based on the value ( e.g. inserting in a sorted list )- will be O(n). If it
is being inserted after or before an existing known node is O(1).
โ€ข Deleting an arbitrary value (rather than a node) will indeed be O(n) as it will
need to find the value. Deleting a node (when the node is known ) is O(1).
โ€ข Inserting to the first or last of the list will always be O(1) - because those are
just special cases of the above.
ADVANTAGES OF DOUBLY LINKED LIST
๏‚ง Dynamic size
๏‚ง Ease of insertion/deletion
๏‚ง A DLL can be traversed in both forward and backward direction.
๏‚ง The delete operation in DLL is more efficient if pointer to the node to be
deleted is given.
In singly linked list, to delete a node, pointer to the previous node is needed.
To get this previous node, sometimes the list is traversed. In DLL, we can get
the previous node using previous pointer.
DISADVANTAGES OF DOUBLY LINKED LIST
๏ฑ Every node of DLL Require extra space for an previous pointer.
๏ฑ All operations require an extra pointer previous to be maintained. For
example, in insertion, we need to modify previous pointers together with next
pointers.
REFERENCES:
โ€ข Class lecture
โ€ข Stackoverflow.com
โ€ข Geekforgeeks.org
Thank you

More Related Content

What's hot

Linkedlist
LinkedlistLinkedlist
Linkedlist
Taslima Yasmin Tarin
ย 
Linked list
Linked listLinked list
Linked list
Ajharul Abedeen
ย 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
Vivek Bhargav
ย 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
Afaq Mansoor Khan
ย 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
ย 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
ย 
Linked list
Linked listLinked list
Linked list
Harry Potter
ย 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
Prof Ansari
ย 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
ย 
linked list using c
linked list using clinked list using c
linked list using c
Venkat Reddy
ย 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
ย 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
Tushar Aneyrao
ย 
Linked lists
Linked listsLinked lists
Linked lists
GowriKumar Chandramouli
ย 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
J.T.A.JONES
ย 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
ย 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
ย 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
Khulna University of Engineering & Tecnology
ย 
linked list
linked listlinked list
linked list
Abbott
ย 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
iCreateWorld
ย 
Linked list
Linked listLinked list
Linked list
eShikshak
ย 

What's hot (20)

Linkedlist
LinkedlistLinkedlist
Linkedlist
ย 
Linked list
Linked listLinked list
Linked list
ย 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
ย 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
ย 
Linked list
Linked list Linked list
Linked list
ย 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
ย 
Linked list
Linked listLinked list
Linked list
ย 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
ย 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
ย 
linked list using c
linked list using clinked list using c
linked list using c
ย 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
ย 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
ย 
Linked lists
Linked listsLinked lists
Linked lists
ย 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
ย 
Linked list
Linked listLinked list
Linked list
ย 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
ย 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
ย 
linked list
linked listlinked list
linked list
ย 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
ย 
Linked list
Linked listLinked list
Linked list
ย 

Similar to 11 15 (doubly linked list)

Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
ย 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
ย 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
Rana junaid Rasheed
ย 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
Getachew Ganfur
ย 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
kulachihansraj
ย 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
tech4us
ย 
linkedlist (1).ppt
linkedlist (1).pptlinkedlist (1).ppt
linkedlist (1).ppt
SwarChaudhary
ย 
Unit7 C
Unit7 CUnit7 C
Unit7 C
arnold 7490
ย 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptxData structures linked list introduction.pptx
Data structures linked list introduction.pptx
Kalpana Mohan
ย 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
Reazul Islam
ย 
Queue
QueueQueue
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
ย 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
JITTAYASHWANTHREDDY
ย 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
DikkySuryadiSKomMKom
ย 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
ย 
3.linked list
3.linked list3.linked list
3.linked list
Chandan Singh
ย 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
Chandan Singh
ย 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
Aakash deep Singhal
ย 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
ย 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
MeghaKulkarni27
ย 

Similar to 11 15 (doubly linked list) (20)

Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ย 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
ย 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
ย 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
ย 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
ย 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
ย 
linkedlist (1).ppt
linkedlist (1).pptlinkedlist (1).ppt
linkedlist (1).ppt
ย 
Unit7 C
Unit7 CUnit7 C
Unit7 C
ย 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptxData structures linked list introduction.pptx
Data structures linked list introduction.pptx
ย 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
ย 
Queue
QueueQueue
Queue
ย 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
ย 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
ย 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
ย 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ย 
3.linked list
3.linked list3.linked list
3.linked list
ย 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
ย 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
ย 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ย 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
ย 

Recently uploaded

Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
ย 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
ย 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
ย 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
Kalna College
ย 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
ย 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
7DFarhanaMohammed
ย 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
ย 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
blueshagoo1
ย 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
ย 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Kalna College
ย 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
MJDuyan
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
ย 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
ย 
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdfู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ
ย 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
ย 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
ย 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
sonukumargpnirsadhan
ย 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
ย 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
ย 

Recently uploaded (20)

Observational Learning
Observational Learning Observational Learning
Observational Learning
ย 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
ย 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
ย 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
ย 
220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science220711130082 Srabanti Bag Internet Resources For Natural Science
220711130082 Srabanti Bag Internet Resources For Natural Science
ย 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
ย 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
ย 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
ย 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
ย 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
ย 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
ย 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
ย 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
ย 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
ย 
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdfู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ   ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ู…ุตุญู ุงู„ู‚ุฑุงุกุงุช ุงู„ุนุดุฑ ุฃุนุฏ ุฃุญุฑู ุงู„ุฎู„ุงู ุณู…ูŠุฑ ุจุณูŠูˆู†ูŠ.pdf
ย 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
ย 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
ย 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
ย 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
ย 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ย 

11 15 (doubly linked list)

  • 1. DOUBLY LINKED LIST CREATED BY: 1507011- TAHMINA RAHMAN 1507012- SAMIUL AZIM 1507013- FABLIHA HAQUE 1507014- SALIM SHADMAN ANKUR 1507015- SAIFUR RAHMAN
  • 2. TOPICS: โ€ข linked lists โ€ข doubly linked list โ€ข Creation and traversing of doubly linked list โ€ข Insertion and deletion on doubly linked list โ€ข complexity of insertion and deletion โ€ข Advantages and disadvantages of doubly linked list
  • 3. LINKED LIST ๏ƒ˜ Like arrays, Linked List is a linear data structure ๏ƒ˜ Unlike arrays, linked list elements are not stored at contiguous location ๏ƒ˜ the elements are linked using pointers ๏ƒ˜ does not have any index
  • 4. ADDRESSES FOR LINKED LIST AND ARRAY Linked List Arrray
  • 5. WHY WE USE LINKED LIST Arrays can be used to store linear data of similar types, but arrays have following limitations.. 1) The size of the arrays is fixed . 2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.
  • 6. DOUBLY LINKED LIST โ€ข A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with next pointer and data which are there in singly linked list. โ€ข Every nodes in the doubly linked list has three fields: 1. Left Pointer (prev) 2. Right Pointer (next) 3. Data (info)
  • 7. DOUBLY LINKED LIST โ€ข Prev - address of the previous node โ€ข Next - address of the next node โ€ข Info - information of the node โ€ข head - address of the first node Prev Info Next node
  • 8. CREATION OF DOUBLY LINKED LIST Steps- 1: Head := NULL (as global) 2: New Node (Ptr) // set data and prev , next to NULL 3: If Head = NULL ๏ƒ˜ Head := ptr ๏ƒ˜ temp := ptr 4. If not ๏ƒ˜ temp โ†’ next := ptr ๏ƒ˜ Ptr โ†’ prev := temp ๏ƒ˜ temp := ptr
  • 9. CREATION OF DOUBLY LINKED LIST NULL data1 NULL 0x80 0x80 data2 NULLNULL data1 0x81 0x810x80 0x80 data2 0x81NULL data1 0x81 0x81 data3 NULL 0x80 0x81 0x82 No element inserted Third element inserted: Second element inserted: First element inserted: Empty list Head temp Head temp Head temp
  • 10. TRAVERSING 0x80 9 0x82NULL 8 0x81 0x81 10 NULL Head Srt Steps: Set srt := head while ( srt->next != NULL) print srt->info // 8 srt := srt->next if (srt->next == NULL) print srt->info end of traversing 0x80 0x81 0x82 False Not Executed Output: 8 Srt 0x80 0x81 Srt
  • 11. TRAVERSING 0x80 9 0x82NULL 8 0x81 0x81 10 NULL Head Srt Steps: Set srt := head while ( srt->next != NULL) print srt->info // 9 srt := srt->next if (srt->next = NULL) print srt->info end of traversing 0x80 0x81 0x82 True Output: 8 9 10 Srt 0x80 0x81 0x82 Srt
  • 12. OPERATIONS ON DOUBLY LINKED LIST Insertion โ€ข Insert an element at first โ€ข Insert an element at last โ€ข Insert before a given element โ€ข Insert after a given element Deletion โ€ข Delete first element โ€ข Delete last element โ€ข Delete a given element โ€ข Delete before a given element โ€ข Delete after a given element
  • 13. INSERT AN ELEMENT AT FIRST prev info NULLprev info nextNULL info next Head Steps- 1. New node (Ptr) prev info next Ptr
  • 14. INSERT AN ELEMENT AT FIRST prev info NULLprev info nextinfo next Head data Steps- 1. New node (Ptr) 2. Ptr โ†’ info := data 3. Ptr โ†’ prev := NULL 4. Ptr โ†’ next := NULL Ptr NULL NULL NULL
  • 15. INSERT AN ELEMENT AT FIRST prev info NULLprev info nextinfo next Head NULL data Steps- 1. New node (Ptr) 2. Ptr โ†’ Info := data 3. Ptr โ†’ prev := NULL 4. Ptr โ†’ next := NULL 5. Head โ†’ prev := ptr 6. Ptr โ†’ next := head 7. Head := Ptr Ptr NULL NULL Head
  • 16. EXAMPLE OF FIRST INSERTION: This is a doubly linked list โ€ฆ. 0x81 8 XX 1 0x81 0x80 5 0x82 Inserting 45 at the first of the list 0x820x810x80 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 45 X 0x90 0X900X80
  • 17. INSERT AN ELEMENT AT LAST prev info NULLprev info nextNULL info next prev info next srt Ptr Steps- 1. New node (Ptr) Head
  • 18. INSERT AN ELEMENT AT LAST prev info NULLprev info nextNULL info next info data next srt Ptr Steps- 1. New node (Ptr) 2. Ptr โ†’ Info := data Head
  • 19. INSERT AN ELEMENT AT LAST prev infoprev info nextNULL info next data srt Ptr Steps- 1. New node (Ptr) 2. Ptr โ†’ Info := data 3. Ptr โ†’ prev := NULL 4. Ptr โ†’ next := NULL 5. srt โ†’ next := ptr 6. Ptr โ†’ prev := srt NULL NULL NULL Head
  • 20. EXAMPLE OF LAST INSERTION: This is a doubly linked list โ€ฆ. Insert 45 at the last of the list 0x81 8 XX 1 0x81 0x80 5 0x82 After insertion 45 at lastโ€ฆ. 0x820x810x80 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 45 X 0x90 0X820X90
  • 21. INSERT BEFORE A GIVEN ELEMENT prev info NULLprev info nextprev info next Steps- 1. New Node(Ptr) 2. ptr โ†’info = data NULL info next data given element Ptr srttemp Head
  • 22. INSERT BEFORE A GIVEN ELEMENT prev info NULLprev info nextinfo next Steps- 1. New Node(Ptr) 2. ptr โ†’info = data 3. srt โ†’prev := Ptr 4. temp โ†’next := Ptr 5. ptr โ†’prev := temp 6. ptr โ†’next := srt NULL info data given element Ptr srttemp next prev Head
  • 23. EXAMPLE INSERT BEFORE A GIVEN ELEMENT: 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 36 X 0x90 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 0x90 Inserting 36 before 5โ€ฆ
  • 24. EXAMPLE INSERT BEFORE A GIVEN ELEMENT: 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 36 X 0x90 0x81 8 XX 1 0x80 5 0x82 0x820x810x80 0x90 Inserting 36 before 5โ€ฆ 0x90
  • 25. EXAMPLE INSERT BEFORE A GIVEN ELEMENT: 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 36 X 0x90 0x81 8 XX 1 5 0x82 0x820x810x80 0x90 Inserting 36 before 5โ€ฆ 0x90 0x90 0X80 0X81
  • 26. SPECIAL CASE: (IF GIVEN ELEMENT IS THE FIRST NODE OF THE LIST) prev info NULLprev info nextprev info nextNULL info next Given element ๏ถ When Head โ†’info = given element ๏ƒ˜ In this case it is similar to first insertion โ€ฆ. Head
  • 27. INSERT AFTER A GIVEN ELEMENT prev info NULLprev info nextprev info nextNULL info next data given element srt Head Steps- 1. New Node (Ptr) 2. Ptr โ†’ info := data Ptr
  • 28. INSERT AFTER A GIVEN ELEMENT prev info NULLinfo nextprev infoNULL info next data given element srt Head Steps- 1. New Node (Ptr) 2. Ptr โ†’ info := data 3. Ptr โ†’ prev := srt 4. Ptr โ†’ next := srt โ†’ next 5. srt โ†’ next โ†’prev := Ptr 6. srt โ†’ next := Ptr Ptr next prev
  • 29. EXAMPLE INSERT AFTER A GIVEN ELEMENT: 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 10 X 0x90 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 Inserting 10 after 5โ€ฆ 0X820X81
  • 30. EXAMPLE INSERT AFTER A GIVEN ELEMENT: 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 10 X 0x90 0x81 8 XX 1 0x81 0x80 5 0x820x810x80 Inserting 10 after 5โ€ฆ 0X820X81 0x90
  • 31. EXAMPLE INSERT AFTER A GIVEN ELEMENT: 0x81 8 XX 1 0x81 0x80 5 0x82 0x820x810x80 X 10 X 0x90 8 XX 1 0x81 0x80 5 0x820x810x80 Inserting 10 after 5โ€ฆ 0X820X81 0x90 0x90
  • 32. SPECIAL CASE: (IF GIVEN ELEMENT IS THE LAST NODE OF THE LIST) prev info NULLprev info nextprev info nextNULL info next Given element ๏ถ When srt โ†’ next = NULL ๏ƒ˜ In this case it is similar to last insertion โ€ฆ. Head srt
  • 33. Now Itโ€™s Time for Deletion
  • 34. DELETE AN ELEMENT AT FIRST Prev Info NextPrev Info NextNULL Info Next Prev Info NULL Steps- 1. Set head := head->next 2. Set head->prev := NULL Head Head
  • 35. DELETE AN ELEMENT AT FIRST Prev Info NextInfo NextNULL Info Next Prev Info NULL Steps- 1. Set head := head->next 2. Set head->prev := NULL Head NULL
  • 36. EXAMPLE OF FIRST DELETION: This is a doubly linked list โ€ฆ. Delete the first node.. 0x820x810x80 0x81 8 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL 0x83 Head Head
  • 37. EXAMPLE OF FIRST DELETION: After deleting first node 0x820x81 0x81 8 0x83NULL 1 0x81 5 0x82 0x82 45 NULL 0x83 Head NULL 0x80
  • 38. DELETE AN ELEMENT AT LAST Prev Info NextPrev Info NextNULL Info Next Prev Info NULL Steps- When srt->next := NULL 1. Set temp->next := NULL Head Temp Srt
  • 39. DELETE AN ELEMENT AT LAST Prev InfoPrev Info NextNULL Info Next Prev Info NULL Steps- When srt->next := NULL 1. Set temp->next := NULL Head Temp Srt NULL
  • 40. EXAMPLE OF LAST DELETION: This is a doubly linked list โ€ฆ. Delete the last node.. 0x820x810x80 0x81 8 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL 0x83 Head Temp Srt
  • 41. EXAMPLE OF LAST DELETION: This is a doubly linked list โ€ฆ. Delete the last node.. 0x820x810x80 0x81 8NULL 1 0x81 0x80 5 0x82 0x82 45 NULL 0x83 Head Temp Srt NULL
  • 42. DELETE A NODE OF GIVEN ELEMENT Prev Info NextPrev info NextNULL Info Next Prev Info NULL Head Steps- when srt->info := item srt->next->prev := srt->prev srt->prev->next := srt->next Srt
  • 43. EXAMPLE OF DELETION OF A GIVEN ELEMENT: This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 8 0x820x810x80 0x81 5 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL 0x83 8 Head Srt
  • 44. EXAMPLE OF DELETION OF A GIVEN ELEMENT: This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 8 0x820x810x80 0x80 5 0x83NULL 1 0x81 0x80 5 0x82 0x82 45 NULL 0x83 8 Head Srt
  • 45. EXAMPLE OF DELETION OF A GIVEN ELEMENT: After deleting the particular node 0x820x810x80 0x80 5 0x83NULL 1 0x80 5 0x82 0x82 45 NULL 0x83 8 Head 0x82 Srt
  • 46. SPECIAL CASES: FOR DELETION OF GIVEN ELEMENT I) If the given element is in the first node, it will be as same as first element delete. II) If the given element is in the last node, it will be as same as last element delete.
  • 47. DELETE A NODE AFTER GIVEN ELEMENT Prev Info NextPrev Info NextNULL Info Next Prev Info NULL Steps- when srt->info := item Set srt->next->next->prev := srt srt->next=srt->next->next Head Srt
  • 48. EXAMPLE OF DELETION AFTER A GIVEN ELEMENT: This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 1 0x820x810x80 0x81 8 0x83NULL 0x81 0x80 5 0x82 0x82 45 NULL 0x83 Head 1 Srt
  • 49. EXAMPLE OF DELETION AFTER A GIVEN ELEMENT: This is a doubly linked list โ€ฆ. Delete the particular node.. Suppose the item is 1 0x820x810x80 0x80 8 0x83NULL 0x81 0x80 5 0x82 0x82 45 NULL 0x83 Head 1 Srt
  • 50. EXAMPLE OF DELETION AFTER A GIVEN ELEMENT: Deleting the particular node after the given element 0x820x810x80 0x80 8 0x83NULL 0x80 5 0x82 0x82 45 NULL 0x83 Head 0x821 Srt
  • 51. SPECIAL CASES: FOR DELETION AFTER GIVEN ELEMENT I) If the given element is before the last node , it will be as same as last element delete. II) If the given element is in the last node, it will not be possible. As the next of last node is NULL , it will not delete anything
  • 52. DELETE A NODE BEFORE GIVEN ELEMENT Prev Info NextPrev Info NextNULL Info Next Prev Info NULL Steps- when srt->info := item Set srt->prev->prev->next := srt srt->prev:= srt-> prev->prev Head Srt
  • 53. EXAMPLE OF DELETION BEFORE A GIVEN ELEMENT: This is a doubly linked list โ€ฆ. Delete the particular node before a given item.. Suppose the item is 9 0x820x810x80 0x81 8 0x83NULL 1 0x81 0x80 5 0x82 0x82 NULL 0x83 Head 9 Srt
  • 54. EXAMPLE OF DELETION BEFORE A GIVEN ELEMENT: This is a doubly linked list โ€ฆ. Delete the particular node before a given item.. Suppose the item is 9 0x820x810x80 0x81 8 0x83NULL 1 0x81 0x80 5 0x83 0x82 NULL 0x83 Head 9 Srt
  • 55. EXAMPLE OF DELETION BEFORE A GIVEN ELEMENT: After Deleting The Node Before A Given Element 0x820x810x80 0x81 8 0x83NULL 1 0x81 0x80 5 0x83 NULL 0x83 Head 90x81 Srt
  • 56. SPECIAL CASES: FOR DELETION AFTER GIVEN ELEMENT I) If the given element is after the first node , it will be as same as first element delete. II) If the given element is in the first node, it will not be possible. As the next of first node is NULL , it will not delete anything
  • 57. COMPLEXITY โ€“ FIRST / LAST INSERTION prev info NULLprev info nextNULL info next Head First insertion Last insertion Last
  • 58. COMPLEXITY โ€“ INSERTION prev info NULLprev info nextNULL info next Head insertion Last
  • 59. COMPLEXITY โ€“ FIRST / LAST DELETION prev info NULLprev info nextNULL info next Head First deletion Last deletion Last
  • 60. COMPLEXITY โ€“ DELETION prev info NULLprev info nextNULL info next Head deletion Last
  • 61. COMPLEXITY OF DOUBLY LINKED LIST โ€ข Inserting based on the value ( e.g. inserting in a sorted list )- will be O(n). If it is being inserted after or before an existing known node is O(1). โ€ข Deleting an arbitrary value (rather than a node) will indeed be O(n) as it will need to find the value. Deleting a node (when the node is known ) is O(1). โ€ข Inserting to the first or last of the list will always be O(1) - because those are just special cases of the above.
  • 62. ADVANTAGES OF DOUBLY LINKED LIST ๏‚ง Dynamic size ๏‚ง Ease of insertion/deletion ๏‚ง A DLL can be traversed in both forward and backward direction. ๏‚ง The delete operation in DLL is more efficient if pointer to the node to be deleted is given. In singly linked list, to delete a node, pointer to the previous node is needed. To get this previous node, sometimes the list is traversed. In DLL, we can get the previous node using previous pointer.
  • 63. DISADVANTAGES OF DOUBLY LINKED LIST ๏ฑ Every node of DLL Require extra space for an previous pointer. ๏ฑ All operations require an extra pointer previous to be maintained. For example, in insertion, we need to modify previous pointers together with next pointers.
  • 64. REFERENCES: โ€ข Class lecture โ€ข Stackoverflow.com โ€ข Geekforgeeks.org

Editor's Notes

  1. Hello good afternoonโ€ฆ.. I am ..... I am here to make a presentation on doubly linked list These are some parts of this presentation
  2. at first I am going to talk about linked listโ€ฆ What is a linked list?? Why we need to use linked list?? I will tell you something behind the figureโ€ฆ.
  3. Variables or pointers addresses of a node are contiguous Bt every nodeโ€™s starting address is randomโ€ฆ.not sequential. Nowโ€ฆ look at the memory allocation of arrayโ€ฆ. The addresses are contiguous. So thatโ€™s the difference
  4. Why linked list?? Well, we can increase the size of the list Bt we can not increase the size of an initialized sized array โ€ฆ. If it is attempted , then index wont be found and cause overflow
  5. A double way or two way linked list a linked list that every element is linked with its previous and next element through pointers
  6. To create a doubly linked list.. Firstly a pointer of node type is declared globally โ€ฆ. Say it is โ€œheadโ€. And initialized to null, as it points to nothing. Now each time a new element is inserted, a new node is created (here denoted by ptr). Data is stored in the info section of ptr And prev and next pointer initialized to null Now for the first nodeโ€ฆ. Head needs to point the first nodeโ€ฆ. Also for the next insertion the previous node address needs to be storedโ€ฆ Thatโ€™s why temp is used to store the address. Then for all other insertion โ€ฆ We set the next pointer of temp to ptr; And prev pointer of ptr to temp; Update temp to ptr to keep track of the previous node.
  7. For traversing we start from the head and continue till the next pointer of a node equals to null... And