SlideShare a Scribd company logo
1 of 54
Linked ListsLinked Lists
&&
QueuesQueues Kalyani Neve
Asst.Prof.
GHRIBM,Jalgaon
Queue :
A queue is a linear list of elements in which deletions can take
place only at one end, called FRONT, and insertion can take only
at the other end, called the REAR.
Queues are also called First-in-First-out (FIFO).
Static Representation of Queue:
AAA BBB CCC
FRONT REAR
BBB CCC
FRONT REAR
After deleting
“AAA”
FRONT
incremented
After inserting
“DDD”
REAR
incremented
& overflow
BBB CCC
FRONT REAR
DDD
Inserting “EEE”
REAR is not
Incremented
Because Queue
Is full
QINSERT(Q, N, FRONT, REAR,ITEM)
This procedure inserts an element ITEM into a queue.
1. [Queue already filled?]
If REAR >= N, then
Write OVERFLOW, and Return.
2. [Find new value of REAR]
If FRONT : = NULL, then [Queue initially empty.]
Set FRONT := 1 and REAR := 1
Else
Set REAR := REAR +1
[End of If structure]
3. [This inserts new element.]
Set Q[REAR] := ITEM
4. Return
QDELETE (Q, N, FRONT,REAR, ITEM)
This procedure deletes an element from a queue and assigns
it to the variable ITEM.
1. [Queue already empty?]
If FRONT := NULL, then : Write UNDERFLOW, and Return
2. Set ITEM := Q[FRONT]
3. [Find new value of Front.]
If FRONT=REAR, then :
Set FRONT := NULL and REAR := NULL.
Else
Set FRONT := FRONT +1.
[End of If structure.]
4. Return
Dynamic Representation of Queue:
Linked Representation
The linked presentation of queue, i.e. queue is implemented
using a SLL.
The nodes are divided into two parts:
1. INFO hold the element of the queue.
2. LINK hold pointers to the next element in the queue.
AAA BBB CCC
FRONT REAR
ILINKQ(INFO,LINK,FRONT,REAR,AVAIL,ITEM)
This procedure inserts an ITEM into a linked queue.
1. [Available space?]
If AVAIL=NULL, then Write OVERFLOW and Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL and AVAIL := LINK[AVAIL]
3. [Copies ITEM into new node]
Set INFO[NEW] := ITEM and LINK[NEW]=NULL
4. If (FRONT = NULL) then FRONT= REAR=NEW
Else set LINK[REAR] := NEW and REAR = NEW
5. Exit
DLINKQ(INFO, LINK, FRONT,REAR, AVAIL, ITEM)
This procedure deletes the front element of a linked list and
assigns
it to the variable ITEM.
1. [Queue has an item to be removed?]
If FRONT = NLL then Write : UNDERFLOW & Exit
2. Set TEMP = FRONT
3. Set ITEM := INFO[TEMP]
4. [Reset FRONT to point to the next element in the queue]
Set FRONT := LINK[TEMP]
5. [Return deleted node to the AVAIL list]
Set LINK[TEMP] := AVAIL and AVAIL := TEMP
6. Exit
The queue operations
1.Queue Create an empty queue
2.~Queue Destroy an existing queue
3.isEmpty Determine whether queue is empty
4.isFull Determine whether the queue is full
5.enqueue Add an item to the end of the queue
6.dequeue Remove the item from front of queue
7. peek Retrieve the item at front of queue
Circular Queue :
In circular queue is one in which the first element comes after the
last element.
Circular queues are the queues implemented in circular form
rather than in a straight line.
Circular queues overcome the problem of unutilized space in
linear queue implemented as an array.
CQINSERT(Q, N, FRONT, REAR,ITEM)
This procedure inserts an element ITEM into a circular queue.
1. [Queue already filled?]
If FRONT = 1 and REAR = N, or if FRONT = REAR + 1, then
Write OVERFLOW, and Return.
2. [Find new value of REAR]
If FRONT : = NULL, then [Queue initially empty.]
Set FRONT := 1 and REAR := 1
Else if REAR =N then:
Set REAR := 1
Else
Set REAR := REAR +1
[End of If structure]
3. [This inserts new element.]
Set Q[REAR] := ITEM
4. Return
CQDELETE (Q, N, FRONT,REAR, ITEM)
This procedure deletes an element from a queue and assigns
it to the variable ITEM.
1. [Queue already empty?]
If FRONT := NULL, then : Write UNDERFLOW, and Return
2. Set ITEM := Q[FRONT]
3. [Find new value of Front.]
If FRONT=REAR, then :
Set FRONT := NULL and REAR := NULL.
Else if FRONT=N then:
Set FRONT := 1
Else
Set FRONT := FRONT +1.
[End of If structure.]
4. Return
Delete E
F R
F
Delete F
Delete C & DE
Empty
F R
F R
Insert AA
Insert BA B
F R
Insert CA B
F R
C
Insert DA B
F R
C D
Delete AB
F R
C D
Insert EE B
R F
C D
Delete BE
R F
C D
F R
Insert FE
FR
C DF
F
F R
Priority queues:
A priority queue is a collection of elements such that each
element has been assigned a priority and such that the
order in which elements are deleted and processed comes
from the following rules :
1. An element of higher priority is processed before any
element of lower priority.
2. Two elements with the same priority are processed
according to the order in which they were added to the
queue.
There are two ways of maintaining a priority queue in memory,
1. One-way list
2. Multiple queues
In One-way list, each node will contain three items of
information.
INFO PRN LINK
Priority No.
In multiple queue, one queue grows from position of 1 of the
array and the other grows from the last position.
Applications of Queues :
1. Round Robin Technique for processor scheduling is
implemented using queues.
2. All types of customer service (like railway ticket reservation)
center software are designed using queues to store customer’s
information.
3. Printer server routines are designed using queues. A number
of
users share a printer using printer server, then server spool’s
all the jobs from all the users to the server’s hard disk in a
queue. From here job number in the queue.
Linked Lists :
A linked list is a linear collection of data elements called nodes,
where the linear order is given by means of pointers.
That is, each node is divided into two parts :
the first part contains the information of the elements, and
the second part, called the link field or nextpointer field,
contains the address of the next node in the list.
START
Advantages :
1. Linked list are dynamic data structure. i.e. they can grow or
shrink during execution.
2. Efficient memory utilization. Here memory is not pre-
allocated. Memory is allocated whenever is required.
3. Insertion and deletions are easier and efficient.
Disadvantages :
1. More memory required
2. Access to an arbitrary data item is little bit time consuming.
Types of linked list :
1. Singly link list
2. Doubly linked list
3. Singly Circular linked list
4. Doubly Circular linked list
Singly Linked List :
Inserting a node at the beginning
INSFIRST(INFO,LINK,START,AVAIL,ITEM)
This algorithm inserts ITEM as the first node in the list.
1. [OVERFLOW]
If AVAIL=NULL then: Write : OVERFLOW, and Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL and AVAIL := Link[AVAIL]
3. [Copies new data into new node.]
Set INFO[NEW] := ITEM
4. [New node now points to original first node.]
Set LINK[NEW] := START
5. [Changes START so it points to the new node]
Set START := NEW
6. Exit
Inserting after a given node :
INLOC(INFO,LINK,START,AVAIL,LOC,ITEM)
This algorithm inserts ITEM so that ITEM follows th node with
location LOC or inserts ITEM as the first node when LOC = NULL.
1. [OVERFLOW]
IF AVAIL=NULL, then Write: OVERFLOW and Exit.
2. [Remove first node from AVAIL list]
Set NEW := AVAIL and AVAIL := LINK[AVAIL]
3. [Copies data into new node.]
Set INFO[NEW] := ITEM
4. If LOC=NULL then
Set LINK[NEW] := START and START := NEW
Else
Set LINK[NEW] := LINK[LOC] and LINK[LOC] := New
[End of If structure.]
5. Exit
Deletion from a linked list :
Deleting the node following a given node :
DEL(INFO,LINK,START,AVAIL,LOC,LOCP)
1. If LOCP = NULL then
Set START := LINK[START]
Else
Set LINK[LOCP] := LINK[LOC]
2. [Return deleted node to the AVAIL list].
Set LINK[LOC] := AVAIL and AVAIL := LOC
3. Exit
Deleting the node with a given ITEM of
Information
FINDB(INFO,LINK,START,ITEM,LOC,LOCP)
1. [List empty] If START = NULL then
Set LOC := NULL and LOCP := NULL, and Return
2. [ITEM in first node?]
If INFO[START] = ITEM then :
Set LOC := START and LOCP := NULL, and Return
3. [Initializes pointers.]
Set SAVE := START and PTR := LINK[START]
4. Repeat steps 5 and 6 while PTR != NULL
5. If INFO[PTR]=ITEM then:
Set LOC := PTR and LOCP := SAVE and
Return
6. Set SAVE := PTR and PTR := LINK[PTR]
7. [Search unsuccessful]
Set LOC := NULL
8. Return
DELETE(INFO,LINK,START,AVAIL,ITEM)
1. Call FINDB(INFO,LINK,START,ITEM,LOC,LOCP)
2. If LOC = NULL then : write ITEM not in list, and Exit
3. [Delete node]
If LOCP=NULL then
Set START := LINK[START].
Else
Set LINK[LOCP]:=LINK[LOC]
4. [Return deleted node to the AVAIL list]
Set LINK[LOC] := AVAIL and AVAIL := LOC
5. Exit
Singly Circular Linked List :
It is a linked list in which the link field of the last node contains
the address of the first node of the list.
START
A circular linked list has no end. Therefore, it is necessary to
established the START & END nodes the linked list.
END
Inserting a node at the beginning
INSFIRST(INFO,LINK,START,AVAIL,ITEM,END)
This algorithm inserts ITEM as the first node in the list.
1. [OVERFLOW]
If AVAIL=NULL then: Write : OVERFLOW, and Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL and AVAIL := LINK[AVAIL]
3. [List is empty?]
If START = NULL then,
Set INFO[NEW] := ITEM
Set LINK[NEW] := NEW
Set START := END := NEW
[End of IF]
4. [Copies new data into new node.]
Set INFO[NEW] := ITEM
5. [New node now points to original first node.]
Set LINK[NEW] := START
6. [Changes START so it points to the new node]
Set START := NEW
7. [Attach link of END node to START]
Set LINK[END] := NEW
8. Exit
START END
10 20 30
40 50 60
AVAIL
Inserting a node at the END
INSEND(INFO,LINK,START,AVAIL,ITEM,END)
1. [OVERFLOW]
If AVAIL=NULL then: Write : OVERFLOW, and
Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL and AVAIL := LINK[AVAIL]
3. [List is empty?]
If START = NULL then,
Set INFO[NEW] := ITEM
Set LINK[NEW] := NEW
Set START := END := NEW
[End of IF]
4. [Copies new data into new node.]
Set INFO[NEW] := ITEM
5. [New node now points to last node.]
Set LINK[END] := NEW
6. [Changes END so it points to the new node]
Set END := NEW
7. [Attach link of END node to START]
Set LINK[END] := START
8. Exit
START END
10 20 30
40 50 60
AVAIL
Inserting a node at the Specified Position
INSEND(INFO,LINK,START,AVAIL,ITEM,TEMP,LOC)
1. [OVERFLOW]
If AVAIL=NULL then: Write : OVERFLOW, and
Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL and AVAIL := LINK[AVAIL]
3. [Copies new data into new node.]
Set INFO[NEW] := ITEM
4. [Initialize the counter & pointer TEMP]
Set Cnt := 1
Set TEMP := START
5. Repeat Steps 6 until Cnt < LOC -1
6. Set TEMP := LINK[TEMP
Set Cnt := Cnt + 1
6. [Insert the node]
Set LINK[NEW] := LINK[TEMP]
Set LINK[TEMP} := NEW
6. Return
START END
10 20 30
40 50 60
AVAIL
Deletion from circular linked list
From the Beginning :
DEL_FIRST(INFO,LINK,START,END,AVAIL,ITEM)
1. [Underflow?]
If START = NULL then, Write UNDERFLOW & Exit
2. [Assign START to ITEM]
Set ITEM := START
3. Set START := LINK[START]
4. [Attach link of END to START]
Set LINK[END] := START
4. [Returns deleted node to AVAIL list]
Set LINK[ITEM] := AVAIL
Set AVAIL := ITEM
4. Exit
START END
10 20 30
40 50 60
AVAIL
Deletion from circular linked list
From the END:
DEL_LAST(INFO,LINK,START,END,AVAIL,ITEM)
1. [Underflow?]
If START = NULL then, Write UNDERFLOW & Exit
2. [Points START to ITEM]
Set ITEM := START
3. [Traverse the list up to end]
Repeat step 5 until LINK[ITEM] != START
4. Set LOC := ITEM
Set ITEM:= LINK[ITEM]
5. [Delete last node by deleting link]
Set LINK[LOC] := START
6. [Returns deleted node to AVAIL list]
Set LINK[ITEM] := AVAIL
Set AVAIL := ITEM
7. Exit
From specified position :
DEL_LOC(INFO,LINK,START,END,AVAIL,ITEM)
1. [Underflow ?]
If START = NULL then Write : UNDERFLOW & Exit
2. [Initialize the counter and TEMP]
Set Cnt := 1
Set TEMP := START
3. Repeat steps 4 to 6 until Cnt < Loc
4. Set PTR := TEMP
5. Set TEMP := LINK[TEMP]
6. Set Cnt := Cnt +1
7. [Delete an element]
ITEM := INFO[TEMP]
8. [Adjust the link]
Set LINK[PTR] := LINK[TEMP]
9. [Return deleted node to AVAIL list]
Set LINK[ITEM] := AVAIL
Set AVAIL := ITEM
10. Exit
Doubly Linked List :
It is a doubly linked list in which all nodes have two link fields.
Structure of node is shown in following fig.
DATA
LEFT RIGHT
The LEFT link points to the predecessor node and the RIGHT
link points to the Successor node.
Insertion algorithms are on next slide:
At the Beginning :
INS_START(INFO,LEFT,RIGHT,AVAIL,ITEM,START)
1. [Overflow?]
If AVAIL = NULL, then Write : OVERFLOW & Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL
Set AVAIL := RIGHT[AVAIL]
3. [Copies new data into new node]
Set INFO[NEW] := ITEM
Set LEFT[NEW] := NULL
Set RIGHT[NEW] := NULL
4. [New node now points to the original start node]
Set RIGHT[NEW] := START
Set LEFT[START] := NEW
5. [Change START to new node]
Set START := NEW
6. Exit
At the End :
INS_END(INFO,LEFT,RIGHT,AVAIL,ITEM,START)
1. [Overflow?]
If AVAIL = NULL, then Write : OVERFLOW & Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL
Set AVAIL := RIGHT[AVAIL]
3. [Copies new data into new node]
Set INFO[NEW] := ITEM
Set LEFT[NEW] := NULL
Set RIGHT[NEW] := NULL
4. Set LOC := START
5. [Traverse complete linked list]
Repeat step 6 until RIGHT[LOC] != NULL
6. Set LOC := RIGHT[LOC]
7. [Insert node at the end]
Set RIGHT[LOC] := New
Set LEFT[NEW] := LOC
8. Exit
At specified position :
INS_LOC(INFO,LEFT,RIGHT,AVAIL,ITEM,START)
1. [OVERFLOW]
If AVAIL=NULL then: Write : OVERFLOW, and
Exit
2. [Remove first node from AVAIL list]
Set NEW := AVAIL and AVAIL := RIGHT[AVAIL]
3. [Copies new data into new node.]
Set INFO[NEW] := ITEM
Set LEFT[NEW] := NULL
Set RIGHT[NEW] := NULL
4. [Initialize the counter & pointer TEMP]
Set Cnt := 1
Set TEMP := START
5. Repeat Steps 6 until Cnt < LOC -1
6. Set TEMP := RIGHT[TEMP]
Set Cnt := Cnt + 1
6. [Insert the node]
Set RIGHT[NEW] := RIGHT[TEMP]
Set RIGHT[TEMP] := NEW
Set LEFT[NEW] := TEMP
6. Return
Deletion from Doubly linked list :
From the Beginning :
DELETE_FIRST(INFO,RIGHT,LEFT,AVAIL,START,ITEM)
1. [Underflow?]
If START = NULL , then Write : UNDERFLOW & return
2. [Assign START to ITEM]
Set ITEM := START
3. Set START := RIGHT[START]
4. [Make left link is null]
Set LEFT[START] := NULL
5. [Returns deleted node to AVAIL list]
Set RIGHT[ITEM] := AVAIL
Set AVAIL := ITEM
6. Exit
From the End :
DELETE_END(INFO,RIGHT,LEFT,AVAIL,START,ITEM)
1. [Underflow?]
If START = NULL , then Write : UNDERFLOW & return
2. [Assign START to ITEM]
Set ITEM := START
3. [Traverse list upto end]
Repeat step 5 until RIGHT[ITEM] != NULL
4. Set LOC := ITEM
Set ITEM := RIGHT[ITEM]
5. [Delete the last node]]
Set RIGHT[LOC] := NULL
6. [Returns deleted node to AVAIL list]
Set RIGHT[ITEM] := AVAIL
Set AVAIL := ITEM
7. Exit
From specified position :
DEL_LOC(INFO,RIGHT,LEFT,START,AVAIL,ITEM)
1. [Underflow ?]
If START = NULL then Write : UNDERFLOW & Exit
2. [Initialize the counter and TEMP]
Set Cnt := 1
Set TEMP := START
3. Repeat steps 4 to 6 until Cnt < Loc
4. Set PTR := TEMP
5. Set TEMP := RIGHT[TEMP]
6. Set Cnt := Cnt +1
7. [Delete an element]
ITEM := INFO[TEMP]
8. [Adjust the link]
Set RIGHT[PTR] := RIGHT[TEMP]
9. [Return deleted node to AVAIL list]
Set RIGHT[ITEM] := AVAIL
Set AVAIL := ITEM
10. Exit
Operations on Linked Lists:
In a well-designed list data structure, you should be able to
manipulate its elements without knowing anything about its
data. Unlike arrays, the entry point into any linked list is the
head of the list.
1. Traversing a linked list.
2. Append a new node (to the end) of a list
3. Propend a new node (to the beginning) of the list
4. Inserting a new node to a specific position on the list
5. Deleting a node from the list
6. Updating a node in the list
Static and Dynamic Memory Allocation :
Static Memory Allocation
• Fast access to elements
• Expensive to insert/remove element
• Have fixed maximum size
• Memory is reserved at the time of compilation.
Eg: Arrays, Records
Dynamic Memory Allocation
• Fast insertion/deletion of element
• Slower access to the element
• Have flexible size
• Memory allocation for the data structure takes place at
the
run time, only required amount of memory is allocated.
Eg: Link lists, Stacks, Queues, Trees

More Related Content

What's hot (20)

Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Linked list
Linked listLinked list
Linked list
 
Singly link list
Singly link listSingly link list
Singly link list
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
single linked list
single linked listsingle linked list
single linked list
 
Linked list
Linked listLinked list
Linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Red black tree
Red black treeRed black tree
Red black tree
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Expression trees
Expression treesExpression trees
Expression trees
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Stack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data StructureStack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data Structure
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 

Similar to Linked Lists and Queues: Data Structures Explained

Similar to Linked Lists and Queues: Data Structures Explained (20)

ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
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
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Linklist
LinklistLinklist
Linklist
 
Lect 11-12 Zaheer Abbas
Lect 11-12 Zaheer AbbasLect 11-12 Zaheer Abbas
Lect 11-12 Zaheer Abbas
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docx
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
 
DSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdfDSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdf
 

More from kalyanineve

Sorting and searching
Sorting and searchingSorting and searching
Sorting and searchingkalyanineve
 
Unit 5 graphs minimum spanning trees
Unit 5   graphs minimum spanning treesUnit 5   graphs minimum spanning trees
Unit 5 graphs minimum spanning treeskalyanineve
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structurekalyanineve
 
Linux command ppt
Linux command pptLinux command ppt
Linux command pptkalyanineve
 

More from kalyanineve (6)

Sorting and searching
Sorting and searchingSorting and searching
Sorting and searching
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 
Unit 5 graphs minimum spanning trees
Unit 5   graphs minimum spanning treesUnit 5   graphs minimum spanning trees
Unit 5 graphs minimum spanning trees
 
Unit 4 tree
Unit 4   treeUnit 4   tree
Unit 4 tree
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 

Recently uploaded

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 

Recently uploaded (20)

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 

Linked Lists and Queues: Data Structures Explained

  • 1. Linked ListsLinked Lists && QueuesQueues Kalyani Neve Asst.Prof. GHRIBM,Jalgaon
  • 2. Queue : A queue is a linear list of elements in which deletions can take place only at one end, called FRONT, and insertion can take only at the other end, called the REAR. Queues are also called First-in-First-out (FIFO). Static Representation of Queue: AAA BBB CCC FRONT REAR BBB CCC FRONT REAR After deleting “AAA” FRONT incremented After inserting “DDD” REAR incremented & overflow BBB CCC FRONT REAR DDD Inserting “EEE” REAR is not Incremented Because Queue Is full
  • 3. QINSERT(Q, N, FRONT, REAR,ITEM) This procedure inserts an element ITEM into a queue. 1. [Queue already filled?] If REAR >= N, then Write OVERFLOW, and Return. 2. [Find new value of REAR] If FRONT : = NULL, then [Queue initially empty.] Set FRONT := 1 and REAR := 1 Else Set REAR := REAR +1 [End of If structure] 3. [This inserts new element.] Set Q[REAR] := ITEM 4. Return
  • 4. QDELETE (Q, N, FRONT,REAR, ITEM) This procedure deletes an element from a queue and assigns it to the variable ITEM. 1. [Queue already empty?] If FRONT := NULL, then : Write UNDERFLOW, and Return 2. Set ITEM := Q[FRONT] 3. [Find new value of Front.] If FRONT=REAR, then : Set FRONT := NULL and REAR := NULL. Else Set FRONT := FRONT +1. [End of If structure.] 4. Return
  • 5. Dynamic Representation of Queue: Linked Representation The linked presentation of queue, i.e. queue is implemented using a SLL. The nodes are divided into two parts: 1. INFO hold the element of the queue. 2. LINK hold pointers to the next element in the queue. AAA BBB CCC FRONT REAR
  • 6. ILINKQ(INFO,LINK,FRONT,REAR,AVAIL,ITEM) This procedure inserts an ITEM into a linked queue. 1. [Available space?] If AVAIL=NULL, then Write OVERFLOW and Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL and AVAIL := LINK[AVAIL] 3. [Copies ITEM into new node] Set INFO[NEW] := ITEM and LINK[NEW]=NULL 4. If (FRONT = NULL) then FRONT= REAR=NEW Else set LINK[REAR] := NEW and REAR = NEW 5. Exit
  • 7. DLINKQ(INFO, LINK, FRONT,REAR, AVAIL, ITEM) This procedure deletes the front element of a linked list and assigns it to the variable ITEM. 1. [Queue has an item to be removed?] If FRONT = NLL then Write : UNDERFLOW & Exit 2. Set TEMP = FRONT 3. Set ITEM := INFO[TEMP] 4. [Reset FRONT to point to the next element in the queue] Set FRONT := LINK[TEMP] 5. [Return deleted node to the AVAIL list] Set LINK[TEMP] := AVAIL and AVAIL := TEMP 6. Exit
  • 8. The queue operations 1.Queue Create an empty queue 2.~Queue Destroy an existing queue 3.isEmpty Determine whether queue is empty 4.isFull Determine whether the queue is full 5.enqueue Add an item to the end of the queue 6.dequeue Remove the item from front of queue 7. peek Retrieve the item at front of queue
  • 9. Circular Queue : In circular queue is one in which the first element comes after the last element. Circular queues are the queues implemented in circular form rather than in a straight line. Circular queues overcome the problem of unutilized space in linear queue implemented as an array.
  • 10. CQINSERT(Q, N, FRONT, REAR,ITEM) This procedure inserts an element ITEM into a circular queue. 1. [Queue already filled?] If FRONT = 1 and REAR = N, or if FRONT = REAR + 1, then Write OVERFLOW, and Return. 2. [Find new value of REAR] If FRONT : = NULL, then [Queue initially empty.] Set FRONT := 1 and REAR := 1 Else if REAR =N then: Set REAR := 1 Else Set REAR := REAR +1 [End of If structure] 3. [This inserts new element.] Set Q[REAR] := ITEM 4. Return
  • 11. CQDELETE (Q, N, FRONT,REAR, ITEM) This procedure deletes an element from a queue and assigns it to the variable ITEM. 1. [Queue already empty?] If FRONT := NULL, then : Write UNDERFLOW, and Return 2. Set ITEM := Q[FRONT] 3. [Find new value of Front.] If FRONT=REAR, then : Set FRONT := NULL and REAR := NULL. Else if FRONT=N then: Set FRONT := 1 Else Set FRONT := FRONT +1. [End of If structure.] 4. Return
  • 12. Delete E F R F Delete F Delete C & DE Empty F R F R Insert AA Insert BA B F R Insert CA B F R C Insert DA B F R C D Delete AB F R C D Insert EE B R F C D Delete BE R F C D F R Insert FE FR C DF F F R
  • 13. Priority queues: A priority queue is a collection of elements such that each element has been assigned a priority and such that the order in which elements are deleted and processed comes from the following rules : 1. An element of higher priority is processed before any element of lower priority. 2. Two elements with the same priority are processed according to the order in which they were added to the queue.
  • 14. There are two ways of maintaining a priority queue in memory, 1. One-way list 2. Multiple queues In One-way list, each node will contain three items of information. INFO PRN LINK Priority No. In multiple queue, one queue grows from position of 1 of the array and the other grows from the last position.
  • 15. Applications of Queues : 1. Round Robin Technique for processor scheduling is implemented using queues. 2. All types of customer service (like railway ticket reservation) center software are designed using queues to store customer’s information. 3. Printer server routines are designed using queues. A number of users share a printer using printer server, then server spool’s all the jobs from all the users to the server’s hard disk in a queue. From here job number in the queue.
  • 16. Linked Lists : A linked list is a linear collection of data elements called nodes, where the linear order is given by means of pointers. That is, each node is divided into two parts : the first part contains the information of the elements, and the second part, called the link field or nextpointer field, contains the address of the next node in the list. START
  • 17. Advantages : 1. Linked list are dynamic data structure. i.e. they can grow or shrink during execution. 2. Efficient memory utilization. Here memory is not pre- allocated. Memory is allocated whenever is required. 3. Insertion and deletions are easier and efficient. Disadvantages : 1. More memory required 2. Access to an arbitrary data item is little bit time consuming.
  • 18. Types of linked list : 1. Singly link list 2. Doubly linked list 3. Singly Circular linked list 4. Doubly Circular linked list
  • 19. Singly Linked List : Inserting a node at the beginning INSFIRST(INFO,LINK,START,AVAIL,ITEM) This algorithm inserts ITEM as the first node in the list. 1. [OVERFLOW] If AVAIL=NULL then: Write : OVERFLOW, and Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL and AVAIL := Link[AVAIL] 3. [Copies new data into new node.] Set INFO[NEW] := ITEM 4. [New node now points to original first node.] Set LINK[NEW] := START 5. [Changes START so it points to the new node] Set START := NEW 6. Exit
  • 20. Inserting after a given node : INLOC(INFO,LINK,START,AVAIL,LOC,ITEM) This algorithm inserts ITEM so that ITEM follows th node with location LOC or inserts ITEM as the first node when LOC = NULL. 1. [OVERFLOW] IF AVAIL=NULL, then Write: OVERFLOW and Exit. 2. [Remove first node from AVAIL list] Set NEW := AVAIL and AVAIL := LINK[AVAIL] 3. [Copies data into new node.] Set INFO[NEW] := ITEM 4. If LOC=NULL then Set LINK[NEW] := START and START := NEW Else Set LINK[NEW] := LINK[LOC] and LINK[LOC] := New [End of If structure.] 5. Exit
  • 21. Deletion from a linked list : Deleting the node following a given node : DEL(INFO,LINK,START,AVAIL,LOC,LOCP) 1. If LOCP = NULL then Set START := LINK[START] Else Set LINK[LOCP] := LINK[LOC] 2. [Return deleted node to the AVAIL list]. Set LINK[LOC] := AVAIL and AVAIL := LOC 3. Exit
  • 22. Deleting the node with a given ITEM of Information FINDB(INFO,LINK,START,ITEM,LOC,LOCP) 1. [List empty] If START = NULL then Set LOC := NULL and LOCP := NULL, and Return 2. [ITEM in first node?] If INFO[START] = ITEM then : Set LOC := START and LOCP := NULL, and Return 3. [Initializes pointers.] Set SAVE := START and PTR := LINK[START] 4. Repeat steps 5 and 6 while PTR != NULL 5. If INFO[PTR]=ITEM then: Set LOC := PTR and LOCP := SAVE and Return 6. Set SAVE := PTR and PTR := LINK[PTR]
  • 23. 7. [Search unsuccessful] Set LOC := NULL 8. Return DELETE(INFO,LINK,START,AVAIL,ITEM) 1. Call FINDB(INFO,LINK,START,ITEM,LOC,LOCP) 2. If LOC = NULL then : write ITEM not in list, and Exit 3. [Delete node] If LOCP=NULL then Set START := LINK[START]. Else Set LINK[LOCP]:=LINK[LOC] 4. [Return deleted node to the AVAIL list] Set LINK[LOC] := AVAIL and AVAIL := LOC 5. Exit
  • 24. Singly Circular Linked List : It is a linked list in which the link field of the last node contains the address of the first node of the list. START A circular linked list has no end. Therefore, it is necessary to established the START & END nodes the linked list. END
  • 25. Inserting a node at the beginning INSFIRST(INFO,LINK,START,AVAIL,ITEM,END) This algorithm inserts ITEM as the first node in the list. 1. [OVERFLOW] If AVAIL=NULL then: Write : OVERFLOW, and Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL and AVAIL := LINK[AVAIL] 3. [List is empty?] If START = NULL then, Set INFO[NEW] := ITEM Set LINK[NEW] := NEW Set START := END := NEW [End of IF]
  • 26. 4. [Copies new data into new node.] Set INFO[NEW] := ITEM 5. [New node now points to original first node.] Set LINK[NEW] := START 6. [Changes START so it points to the new node] Set START := NEW 7. [Attach link of END node to START] Set LINK[END] := NEW 8. Exit
  • 27. START END 10 20 30 40 50 60 AVAIL
  • 28. Inserting a node at the END INSEND(INFO,LINK,START,AVAIL,ITEM,END) 1. [OVERFLOW] If AVAIL=NULL then: Write : OVERFLOW, and Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL and AVAIL := LINK[AVAIL] 3. [List is empty?] If START = NULL then, Set INFO[NEW] := ITEM Set LINK[NEW] := NEW Set START := END := NEW [End of IF]
  • 29. 4. [Copies new data into new node.] Set INFO[NEW] := ITEM 5. [New node now points to last node.] Set LINK[END] := NEW 6. [Changes END so it points to the new node] Set END := NEW 7. [Attach link of END node to START] Set LINK[END] := START 8. Exit
  • 30. START END 10 20 30 40 50 60 AVAIL
  • 31. Inserting a node at the Specified Position INSEND(INFO,LINK,START,AVAIL,ITEM,TEMP,LOC) 1. [OVERFLOW] If AVAIL=NULL then: Write : OVERFLOW, and Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL and AVAIL := LINK[AVAIL] 3. [Copies new data into new node.] Set INFO[NEW] := ITEM
  • 32. 4. [Initialize the counter & pointer TEMP] Set Cnt := 1 Set TEMP := START 5. Repeat Steps 6 until Cnt < LOC -1 6. Set TEMP := LINK[TEMP Set Cnt := Cnt + 1 6. [Insert the node] Set LINK[NEW] := LINK[TEMP] Set LINK[TEMP} := NEW 6. Return
  • 33. START END 10 20 30 40 50 60 AVAIL
  • 34. Deletion from circular linked list From the Beginning : DEL_FIRST(INFO,LINK,START,END,AVAIL,ITEM) 1. [Underflow?] If START = NULL then, Write UNDERFLOW & Exit 2. [Assign START to ITEM] Set ITEM := START 3. Set START := LINK[START]
  • 35. 4. [Attach link of END to START] Set LINK[END] := START 4. [Returns deleted node to AVAIL list] Set LINK[ITEM] := AVAIL Set AVAIL := ITEM 4. Exit
  • 36. START END 10 20 30 40 50 60 AVAIL
  • 37. Deletion from circular linked list From the END: DEL_LAST(INFO,LINK,START,END,AVAIL,ITEM) 1. [Underflow?] If START = NULL then, Write UNDERFLOW & Exit 2. [Points START to ITEM] Set ITEM := START 3. [Traverse the list up to end] Repeat step 5 until LINK[ITEM] != START 4. Set LOC := ITEM Set ITEM:= LINK[ITEM]
  • 38. 5. [Delete last node by deleting link] Set LINK[LOC] := START 6. [Returns deleted node to AVAIL list] Set LINK[ITEM] := AVAIL Set AVAIL := ITEM 7. Exit
  • 39. From specified position : DEL_LOC(INFO,LINK,START,END,AVAIL,ITEM) 1. [Underflow ?] If START = NULL then Write : UNDERFLOW & Exit 2. [Initialize the counter and TEMP] Set Cnt := 1 Set TEMP := START 3. Repeat steps 4 to 6 until Cnt < Loc 4. Set PTR := TEMP 5. Set TEMP := LINK[TEMP] 6. Set Cnt := Cnt +1
  • 40. 7. [Delete an element] ITEM := INFO[TEMP] 8. [Adjust the link] Set LINK[PTR] := LINK[TEMP] 9. [Return deleted node to AVAIL list] Set LINK[ITEM] := AVAIL Set AVAIL := ITEM 10. Exit
  • 41. Doubly Linked List : It is a doubly linked list in which all nodes have two link fields. Structure of node is shown in following fig. DATA LEFT RIGHT The LEFT link points to the predecessor node and the RIGHT link points to the Successor node. Insertion algorithms are on next slide:
  • 42. At the Beginning : INS_START(INFO,LEFT,RIGHT,AVAIL,ITEM,START) 1. [Overflow?] If AVAIL = NULL, then Write : OVERFLOW & Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL Set AVAIL := RIGHT[AVAIL] 3. [Copies new data into new node] Set INFO[NEW] := ITEM Set LEFT[NEW] := NULL Set RIGHT[NEW] := NULL
  • 43. 4. [New node now points to the original start node] Set RIGHT[NEW] := START Set LEFT[START] := NEW 5. [Change START to new node] Set START := NEW 6. Exit
  • 44. At the End : INS_END(INFO,LEFT,RIGHT,AVAIL,ITEM,START) 1. [Overflow?] If AVAIL = NULL, then Write : OVERFLOW & Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL Set AVAIL := RIGHT[AVAIL] 3. [Copies new data into new node] Set INFO[NEW] := ITEM Set LEFT[NEW] := NULL Set RIGHT[NEW] := NULL 4. Set LOC := START
  • 45. 5. [Traverse complete linked list] Repeat step 6 until RIGHT[LOC] != NULL 6. Set LOC := RIGHT[LOC] 7. [Insert node at the end] Set RIGHT[LOC] := New Set LEFT[NEW] := LOC 8. Exit
  • 46. At specified position : INS_LOC(INFO,LEFT,RIGHT,AVAIL,ITEM,START) 1. [OVERFLOW] If AVAIL=NULL then: Write : OVERFLOW, and Exit 2. [Remove first node from AVAIL list] Set NEW := AVAIL and AVAIL := RIGHT[AVAIL] 3. [Copies new data into new node.] Set INFO[NEW] := ITEM Set LEFT[NEW] := NULL Set RIGHT[NEW] := NULL
  • 47. 4. [Initialize the counter & pointer TEMP] Set Cnt := 1 Set TEMP := START 5. Repeat Steps 6 until Cnt < LOC -1 6. Set TEMP := RIGHT[TEMP] Set Cnt := Cnt + 1 6. [Insert the node] Set RIGHT[NEW] := RIGHT[TEMP] Set RIGHT[TEMP] := NEW Set LEFT[NEW] := TEMP 6. Return
  • 48. Deletion from Doubly linked list : From the Beginning : DELETE_FIRST(INFO,RIGHT,LEFT,AVAIL,START,ITEM) 1. [Underflow?] If START = NULL , then Write : UNDERFLOW & return 2. [Assign START to ITEM] Set ITEM := START 3. Set START := RIGHT[START] 4. [Make left link is null] Set LEFT[START] := NULL 5. [Returns deleted node to AVAIL list] Set RIGHT[ITEM] := AVAIL Set AVAIL := ITEM 6. Exit
  • 49. From the End : DELETE_END(INFO,RIGHT,LEFT,AVAIL,START,ITEM) 1. [Underflow?] If START = NULL , then Write : UNDERFLOW & return 2. [Assign START to ITEM] Set ITEM := START 3. [Traverse list upto end] Repeat step 5 until RIGHT[ITEM] != NULL
  • 50. 4. Set LOC := ITEM Set ITEM := RIGHT[ITEM] 5. [Delete the last node]] Set RIGHT[LOC] := NULL 6. [Returns deleted node to AVAIL list] Set RIGHT[ITEM] := AVAIL Set AVAIL := ITEM 7. Exit
  • 51. From specified position : DEL_LOC(INFO,RIGHT,LEFT,START,AVAIL,ITEM) 1. [Underflow ?] If START = NULL then Write : UNDERFLOW & Exit 2. [Initialize the counter and TEMP] Set Cnt := 1 Set TEMP := START 3. Repeat steps 4 to 6 until Cnt < Loc 4. Set PTR := TEMP 5. Set TEMP := RIGHT[TEMP] 6. Set Cnt := Cnt +1
  • 52. 7. [Delete an element] ITEM := INFO[TEMP] 8. [Adjust the link] Set RIGHT[PTR] := RIGHT[TEMP] 9. [Return deleted node to AVAIL list] Set RIGHT[ITEM] := AVAIL Set AVAIL := ITEM 10. Exit
  • 53. Operations on Linked Lists: In a well-designed list data structure, you should be able to manipulate its elements without knowing anything about its data. Unlike arrays, the entry point into any linked list is the head of the list. 1. Traversing a linked list. 2. Append a new node (to the end) of a list 3. Propend a new node (to the beginning) of the list 4. Inserting a new node to a specific position on the list 5. Deleting a node from the list 6. Updating a node in the list
  • 54. Static and Dynamic Memory Allocation : Static Memory Allocation • Fast access to elements • Expensive to insert/remove element • Have fixed maximum size • Memory is reserved at the time of compilation. Eg: Arrays, Records Dynamic Memory Allocation • Fast insertion/deletion of element • Slower access to the element • Have flexible size • Memory allocation for the data structure takes place at the run time, only required amount of memory is allocated. Eg: Link lists, Stacks, Queues, Trees