SlideShare una empresa de Scribd logo
1 de 42
ALLAH
the most Gracious, the most
merciful
In the name of
Assignment
Submitted by:
 Toseef Hassan (BSF1600847)
 Muhammad Ishfaq (BSF1604280)
 Muhammad Shahzad (BSF1600951)
 Muhammad Umar (BSF1600824)
Class: BS Information Technology (Eve)-A
Semester: IV Semester
Submitted to:
 Mr. Khalid Mehmood
(Head Of Department)
Information Technology
Division of Science & Technology
QUEUES
Overview:
 Simple Queue
 Circular Queue
 Priority Queue
 Deques
• Input restricted deque
• Output restricted deque
What is a Queue?
 A queue is a linear list which obeys FIFO (First In First
Out) principle to insert & delete values.
 An ordered collection of homogeneous elements.
It’s a non-primitive linear data structure.
Simple Queue
45 20 67 7Q
RearFront
Serving Agent
The Queue Operations:
Insertion or Enqueue:
Placing an item in a queue is called “insertion or
enqueue”, which is done at the end of the queue called
“rear” or “tail”.
Deletion or Dequeue:
Removing an item from a queue is called “deletion or
dequeue”, which is done at the other end of the queue
called “front” or “head”.
Insertion or Enqueue:
Algorithm:
If (rear = N-1 )
print (“*Queue is Full*”);
Else
rear = rear + 1; //rear=0
Q[rear] = item
The Queue Operations:
45Q
Rear
0 1 2 3
Where N is the length of array (4 in this
case)
Rear= -1 (First time only)
Front= -1
Item 45
Insertion or Enqueue:
Algorithm:
If (rear = N-1 ) // rear=0
print (“*Queue is Full*”);
Else
rear = rear + 1; //rear=1
Q[rear] = item
The Queue Operations:
45 32Q
Rear
0 1 2 3
N= 4
Front= -1
Item 32
Insertion or Enqueue:
Algorithm:
If (rear = N-1 ) // rear=1
print (“*Queue is Full*”);
Else
rear = rear + 1; //rear=2
Q[rear] = item
The Queue Operations:
45 32 23Q
Rear
0 1 2 3
N= 4
Front= -1
Item 23
Insertion or Enqueue:
Algorithm:
If (rear = N-1 ) // rear=2
print (“*Queue is Full*”);
Else
rear = rear + 1; //rear=3
Q[rear] = item
The Queue Operations:
45 32 23 07Q
Rear
0 1 2 3
N= 4
Front= -1
Item 07
NOW
If we again call the insert() function, insertion
is unsuccessful because queue is full.
Insertion or Enqueue:
Algorithm:
If (rear = N-1 ) // rear=3
print (“*Queue is Full*”);
Else
rear = rear + 1;
Q[rear] = item
The Queue Operations:
45 32 23 07Q
Rear
0 1 2 3
N= 4
Front= -1
Item 10
*Insertion Unsuccessful*
Deletion or Dequeue:
Algorithm:
If (front =rear) // -1 = 3
print (“Queue is empty”);
Else
Front = front + 1;
item = Q [front];
Return item;
The Queue Operations:
45 32 23 07Q
Rear
0 1 2 3
N= 4
Front= -1
Front
Deletion or Dequeue:
Algorithm:
If (front =rear) // 0 = 3
print (“Queue is empty”);
Else
Front = front + 1;
item = Q [front];
Return item;
The Queue Operations:
32 23 07Q
Rear
0 1 2 3
N= 4
Front= 0
Front
Deletion or Dequeue:
Algorithm:
If (front =rear) // 1 = 3
print (“Queue is empty”);
Else
Front = front + 1;
item = Q [front];
Return item;
The Queue Operations:
23 07Q
Rear
0 1 2 3
N= 4
Front= 1
Front
Deletion or Dequeue:
Algorithm:
If (front =rear) // 2 = 3
print (“Queue is empty”);
Else
Front = front + 1;
item = Q [front];
Return item;
The Queue Operations:
07Q
Rear
0 1 2 3
N= 4
Front= 2
Front
Deletion or Dequeue:
Algorithm:
If (front =rear) // 3 = 3
print (“Queue is empty”);
Else
Front = front + 1;
item = Q [front];
Return item;
The Queue Operations:
Q
Rear
0 1 2 3
N= 4
Front= 3
Front
We have seen that all the values of queue are deleted
one by one, hence it can accommodate four more
values being empty.
But still, we can’t insert new values because;
Rear=3 and “Queue is full” condition invokes.
This is the major fault of simple queue that we can
only insert values once in a queue because there is no
mechanism to bring “rear” back to beginning (0).
Disadvantages of Simple Queue:
Circular Queue:
Circular queues were introduced to overcome the
limitations of simple queue.
As the name indicates a circular queue is not linear in
structure but instead it is circular.
Front and Rear variables display a circular movement
(clock wise) over the queue data structure.
As the Rear or Front variable reaches the end of the
queue, it is send back to beginning of the queue
using the mod function.
A B DCCirc_Q
Front Rear
(a) Initial circular queue
DCCirc_Q
Front Rear
(b) Circular queue after two
deletions
E DCCirc_Q
FrontRear
(c) Circ_Q after insertion of e
E F DCCirc_Q
FrontRear
(d) Circ_Q after insertion of
f
Workingofacircularqueue
Insertion:
 Algorithm:
Insert (front, rear, n, item)
{ int p=rear;
rear= (rear+1)%n; // rear=1
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
45Q
Rear
0 1 2 3
Where N is the length of array (4
in this case)
Rear= 0 (First time only)
Front= 0
Item 45
Front
Insertion:
 Algorithm:
Insert (front, rear, n, item)
{ int p=rear;
rear= (rear+1)%n; // rear=2
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
45 32Q
Rear
0 1 2 3
Item 32
Front
Insertion:
 Algorithm:
Insert (front, rear, n, item)
{ int p=rear;
rear= (rear+1)%n; // rear=3
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
45 32 23Q
Rear
0 1 2 3
Item 23
Front
Insertion:
 Algorithm:
Insert (front, rear, n, item)
{ int p=rear; // p=3
rear= (rear+1)%n; // rear=0
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
45 32 23Q
Rear
0 1 2 3
Item 23
Front
Deletion:
 Algorithm:
Delete (front, rear, n, item)
{ If (front==rear)
Print “*Queue is empty*”;
front = (front+1) % n; // front=1
Item = Q [front];
}
45 32 23Q
Rear
0 1 2 3
Front
Deletion:
 Algorithm:
Delete (front, rear, n, item)
{ If (front==rear)
Print “*Queue is empty*”;
front = (front+1) % n; // front=2
Item = Q [front];
}
32 23Q
Rear
0 1 2 3
Front
Deletion:
 Algorithm:
Delete (front, rear, n, item)
{ If (front==rear)
Print “*Queue is empty*”;
front = (front+1) % n; // front=3
Item = Q [front];
}
23Q
Rear
0 1 2 3
Front
Deletion:
 Algorithm:
Delete (front, rear, n, item)
{ If (front==rear)
Print “*Queue is empty*”;
front = (front+1) % n; // front=3
Item = Q [front];
}
Q
Rear
0 1 2 3
Front
Let’s try Insertion again
Insert (front, rear, n, item)
{ int p=rear;
rear= (rear+1)%n; // rear=0
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
70Q
Rear Front
Item 70
0 1 2 3
Rear= 3
Front= 3
Let’s try Insertion again
Insert (front, rear, n, item)
{ int p=rear;
rear= (rear+1)%n; // rear=1
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
70 89Q
Rear Front
Item 89
0 1 2 3
Rear= 0
Front= 3
Let’s try Insertion again
Insert (front, rear, n, item)
{ int p=rear;
rear= (rear+1)%n; // rear=2
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
70 89 27Q
Rear Front
Item 27
0 1 2 3
Rear= 1
Front= 3
Let’s try Insertion again
Insert (front, rear, n, item)
{ int p=rear;
rear= (rear+1)%n; // rear=3
If (front==rear)
{ Print “*Queue is full*”
rear=p;}
Q [rear] = item;
}
70 89 27Q
Rear Front
0 1 2 3
Rear= 2
Front= 3
Priority Queue:
 A priority queue is a queue in which insertion or deletion of
items from any position in the queue are done based on some
property (such as priority of task).
Doctor Example:
Normal Patients Queue
Emergency Patients Queue
1 2 3 4 5
Doctor
SUSPENDED
Deques:
 A deque (double ended queue) is a linear list in which all insertions and
deletions are made at the end of the list. A dequeue is pronounced as
‘deck’ or ‘de queue.’
 A deque is more general than a stack or queue and is a sort of FLIDLO
(First In Last In First Out Last Out).
 A deque has two variants; input restricted queue and output restricted
queue.
 An input restricted dequeue is one where insertions are allowed at one
end only while deletions are allowed at both ends.
 An output restricted dequeue allows insertions at both ends of the queue
but permits deletions only at one end.
Bottom Top
Push
Pop
Stack
Front Rear
Insert
Delete
Queue
Front Rear
Insert
Delete
Dequeue
Delete
Insert
Front Rear
Insert
Delete
Input restricted Dequeue
Delete
Front Rear
Insert
Output restricted Dequeue
Delete
Insert
THANK YOU!

Más contenido relacionado

La actualidad más candente (20)

Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Team 6
Team 6Team 6
Team 6
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Circular queue
Circular queueCircular queue
Circular queue
 
Queue
QueueQueue
Queue
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
05 queues
05 queues05 queues
05 queues
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data Structure
 
Queue
QueueQueue
Queue
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 

Similar a ALLAH the most Gracious, the most merciful

Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptxNuraMohamed9
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data StructureMandeep Singh
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structuresmuskans14
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptxsinghprpg
 
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,queueRai University
 
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,queueRai University
 
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,queueRai University
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 

Similar a ALLAH the most Gracious, the most merciful (20)

Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structures
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Queues.ppt
Queues.pptQueues.ppt
Queues.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
 
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
 
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
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Queue
QueueQueue
Queue
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Lect 17-18 Zaheer Abbas
Lect 17-18 Zaheer AbbasLect 17-18 Zaheer Abbas
Lect 17-18 Zaheer Abbas
 
Queue
QueueQueue
Queue
 

Último

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Último (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

ALLAH the most Gracious, the most merciful

  • 1. ALLAH the most Gracious, the most merciful In the name of
  • 2. Assignment Submitted by:  Toseef Hassan (BSF1600847)  Muhammad Ishfaq (BSF1604280)  Muhammad Shahzad (BSF1600951)  Muhammad Umar (BSF1600824) Class: BS Information Technology (Eve)-A Semester: IV Semester Submitted to:  Mr. Khalid Mehmood (Head Of Department) Information Technology Division of Science & Technology
  • 4. Overview:  Simple Queue  Circular Queue  Priority Queue  Deques • Input restricted deque • Output restricted deque
  • 5. What is a Queue?  A queue is a linear list which obeys FIFO (First In First Out) principle to insert & delete values.  An ordered collection of homogeneous elements. It’s a non-primitive linear data structure.
  • 6. Simple Queue 45 20 67 7Q RearFront
  • 8. The Queue Operations: Insertion or Enqueue: Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear” or “tail”. Deletion or Dequeue: Removing an item from a queue is called “deletion or dequeue”, which is done at the other end of the queue called “front” or “head”.
  • 9. Insertion or Enqueue: Algorithm: If (rear = N-1 ) print (“*Queue is Full*”); Else rear = rear + 1; //rear=0 Q[rear] = item The Queue Operations: 45Q Rear 0 1 2 3 Where N is the length of array (4 in this case) Rear= -1 (First time only) Front= -1 Item 45
  • 10. Insertion or Enqueue: Algorithm: If (rear = N-1 ) // rear=0 print (“*Queue is Full*”); Else rear = rear + 1; //rear=1 Q[rear] = item The Queue Operations: 45 32Q Rear 0 1 2 3 N= 4 Front= -1 Item 32
  • 11. Insertion or Enqueue: Algorithm: If (rear = N-1 ) // rear=1 print (“*Queue is Full*”); Else rear = rear + 1; //rear=2 Q[rear] = item The Queue Operations: 45 32 23Q Rear 0 1 2 3 N= 4 Front= -1 Item 23
  • 12. Insertion or Enqueue: Algorithm: If (rear = N-1 ) // rear=2 print (“*Queue is Full*”); Else rear = rear + 1; //rear=3 Q[rear] = item The Queue Operations: 45 32 23 07Q Rear 0 1 2 3 N= 4 Front= -1 Item 07
  • 13. NOW If we again call the insert() function, insertion is unsuccessful because queue is full.
  • 14. Insertion or Enqueue: Algorithm: If (rear = N-1 ) // rear=3 print (“*Queue is Full*”); Else rear = rear + 1; Q[rear] = item The Queue Operations: 45 32 23 07Q Rear 0 1 2 3 N= 4 Front= -1 Item 10 *Insertion Unsuccessful*
  • 15. Deletion or Dequeue: Algorithm: If (front =rear) // -1 = 3 print (“Queue is empty”); Else Front = front + 1; item = Q [front]; Return item; The Queue Operations: 45 32 23 07Q Rear 0 1 2 3 N= 4 Front= -1 Front
  • 16. Deletion or Dequeue: Algorithm: If (front =rear) // 0 = 3 print (“Queue is empty”); Else Front = front + 1; item = Q [front]; Return item; The Queue Operations: 32 23 07Q Rear 0 1 2 3 N= 4 Front= 0 Front
  • 17. Deletion or Dequeue: Algorithm: If (front =rear) // 1 = 3 print (“Queue is empty”); Else Front = front + 1; item = Q [front]; Return item; The Queue Operations: 23 07Q Rear 0 1 2 3 N= 4 Front= 1 Front
  • 18. Deletion or Dequeue: Algorithm: If (front =rear) // 2 = 3 print (“Queue is empty”); Else Front = front + 1; item = Q [front]; Return item; The Queue Operations: 07Q Rear 0 1 2 3 N= 4 Front= 2 Front
  • 19. Deletion or Dequeue: Algorithm: If (front =rear) // 3 = 3 print (“Queue is empty”); Else Front = front + 1; item = Q [front]; Return item; The Queue Operations: Q Rear 0 1 2 3 N= 4 Front= 3 Front
  • 20. We have seen that all the values of queue are deleted one by one, hence it can accommodate four more values being empty. But still, we can’t insert new values because; Rear=3 and “Queue is full” condition invokes. This is the major fault of simple queue that we can only insert values once in a queue because there is no mechanism to bring “rear” back to beginning (0). Disadvantages of Simple Queue:
  • 21. Circular Queue: Circular queues were introduced to overcome the limitations of simple queue. As the name indicates a circular queue is not linear in structure but instead it is circular. Front and Rear variables display a circular movement (clock wise) over the queue data structure. As the Rear or Front variable reaches the end of the queue, it is send back to beginning of the queue using the mod function.
  • 22. A B DCCirc_Q Front Rear (a) Initial circular queue DCCirc_Q Front Rear (b) Circular queue after two deletions E DCCirc_Q FrontRear (c) Circ_Q after insertion of e E F DCCirc_Q FrontRear (d) Circ_Q after insertion of f Workingofacircularqueue
  • 23. Insertion:  Algorithm: Insert (front, rear, n, item) { int p=rear; rear= (rear+1)%n; // rear=1 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 45Q Rear 0 1 2 3 Where N is the length of array (4 in this case) Rear= 0 (First time only) Front= 0 Item 45 Front
  • 24. Insertion:  Algorithm: Insert (front, rear, n, item) { int p=rear; rear= (rear+1)%n; // rear=2 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 45 32Q Rear 0 1 2 3 Item 32 Front
  • 25. Insertion:  Algorithm: Insert (front, rear, n, item) { int p=rear; rear= (rear+1)%n; // rear=3 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 45 32 23Q Rear 0 1 2 3 Item 23 Front
  • 26. Insertion:  Algorithm: Insert (front, rear, n, item) { int p=rear; // p=3 rear= (rear+1)%n; // rear=0 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 45 32 23Q Rear 0 1 2 3 Item 23 Front
  • 27. Deletion:  Algorithm: Delete (front, rear, n, item) { If (front==rear) Print “*Queue is empty*”; front = (front+1) % n; // front=1 Item = Q [front]; } 45 32 23Q Rear 0 1 2 3 Front
  • 28. Deletion:  Algorithm: Delete (front, rear, n, item) { If (front==rear) Print “*Queue is empty*”; front = (front+1) % n; // front=2 Item = Q [front]; } 32 23Q Rear 0 1 2 3 Front
  • 29. Deletion:  Algorithm: Delete (front, rear, n, item) { If (front==rear) Print “*Queue is empty*”; front = (front+1) % n; // front=3 Item = Q [front]; } 23Q Rear 0 1 2 3 Front
  • 30. Deletion:  Algorithm: Delete (front, rear, n, item) { If (front==rear) Print “*Queue is empty*”; front = (front+1) % n; // front=3 Item = Q [front]; } Q Rear 0 1 2 3 Front
  • 31. Let’s try Insertion again Insert (front, rear, n, item) { int p=rear; rear= (rear+1)%n; // rear=0 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 70Q Rear Front Item 70 0 1 2 3 Rear= 3 Front= 3
  • 32. Let’s try Insertion again Insert (front, rear, n, item) { int p=rear; rear= (rear+1)%n; // rear=1 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 70 89Q Rear Front Item 89 0 1 2 3 Rear= 0 Front= 3
  • 33. Let’s try Insertion again Insert (front, rear, n, item) { int p=rear; rear= (rear+1)%n; // rear=2 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 70 89 27Q Rear Front Item 27 0 1 2 3 Rear= 1 Front= 3
  • 34. Let’s try Insertion again Insert (front, rear, n, item) { int p=rear; rear= (rear+1)%n; // rear=3 If (front==rear) { Print “*Queue is full*” rear=p;} Q [rear] = item; } 70 89 27Q Rear Front 0 1 2 3 Rear= 2 Front= 3
  • 35. Priority Queue:  A priority queue is a queue in which insertion or deletion of items from any position in the queue are done based on some property (such as priority of task).
  • 36. Doctor Example: Normal Patients Queue Emergency Patients Queue 1 2 3 4 5 Doctor SUSPENDED
  • 37. Deques:  A deque (double ended queue) is a linear list in which all insertions and deletions are made at the end of the list. A dequeue is pronounced as ‘deck’ or ‘de queue.’  A deque is more general than a stack or queue and is a sort of FLIDLO (First In Last In First Out Last Out).  A deque has two variants; input restricted queue and output restricted queue.  An input restricted dequeue is one where insertions are allowed at one end only while deletions are allowed at both ends.  An output restricted dequeue allows insertions at both ends of the queue but permits deletions only at one end.
  • 41. Front Rear Insert Output restricted Dequeue Delete Insert