QUEUES Docs
QUEUES Docs
GROUP 4 PRESENTORS
Case Study(
Dequeues Priority Queue Multiple Queue Josephus
Problem)
2
INTRODUCTION TO QUEUES
PRESENTOR: GLAIZA A. CARTAGENA
What is Queue?
3
Analogy For Queue
4
Operations On A Queue
• Enqueue- adding an element in the queue if there is space in the
queue.
• Dequeue- Removing elements from a queue if there are any
elements in the queue
• Front- get the first item from the queue.
• Rear- get the last item from the queue.
• isEmpty/isFull- checks if the queue is empty or full.
Applications
• A queue is used in scheduling processes in a CPU.
• It is used in data transfer between processes.
• It holds multiple jobs which are then called when needed.
5
6
7
8
Output
9
LINKED REPRESENTATION OF QUEUES
PRESENTOR: DAREN JOY BITOS
The HEAD pointer of the linked list is used as the FRONT. Also, use
another pointer called REAR to store the address of the last
element of the queue.
10
11
12
13
14
15
Types of Queues
A queue data structure can be classified into
the following types:
• Circular Queue
• Priority Queue
• Dequeue.
16
CIRCULAR QUEUE
PRESENTOR : GLENNIE ROSE DOBLE
Bynow we pretty much have a fair idea of the structure of the circular queue,
and it implements FIFO ordering. What FIFO essentially means is elements that
go in first are removed the first. This structure is similar to a queue at an
airport, wherein the person standing at the first gets to board the flight and so
on till the last passenger boards the flight. But now what we talked about a
queue at the airport, is like a linear queue. There is a limited number of seats
in a flight and hence as the capacity gets full no one is allowed to be a part of
the line or in other words doesn't even get the ticket. Now assume a similar
case where we have limited resources in a computer, and one is performing
memory-intensive tasks all of which takes some time.
17
Now the task which starts first followed by tasks that subsequently start
coming consecutively starts getting piled up and now if the resource gets
full, the other task is out into the waitlist. Assume that had the scenario
been like the one we talked about in flights, any task in the waitlist will
never execute as the line has completely ended. Now let us say we link the
last element to the first element saying that if the last element is filled
check if the first element is free and if yes, then start putting or inserting
the task in resource management and keep the workflow continuous.
With the same intention circular queue works in C. This
methodology is known as circular increment where one tries to keep
incrementing the counter or the pointer that points to the tail of the array in
case of entering any new element (This process is known as enqueuing) and
increasing the pointer that points to the head of the array when any
element is removed (This process is known as dequeuing). Apart from the
elements we just talked about i.e. enqueuing, dequeuing, front (pointer), rear
(pointer) we also have an operation isEmpty or isFull which does a check on
the queue to understand if the queue is empty or full.
18
19
20
21
22
Output
23
PRIORITY QUEUE
PRESENTOR: KIZZEL NOYNAY
24
The real-world example of a priority queue would be a line in a bank where
there is a special privilege for disabled and old people. The disabled people
have the highest priority followed by elderly people and the normal person has
the lowest priority.
•Max Priority Queue: Max priority Queue is the opposite of min priority Queue
in it maximum number value gets the highest priority and a minimum
number of value gets the minimum priority.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
DEQUEUE
PRESENTOR: NOELYN MICARSOS
The word dequeue is short form of double ended queue. In a dequeue, insertion
as well as deletion can be carried out either at the rear end or the front end.
Operations on a Dequeue
1. initialize(): Make the queue empty
2. empty(): Determine if queue is empty
3. full(): Determine if queue is full
4. enqueueF(): Insert an element at the front end of the queue
5. enqueueR(): Insert an element at the rear end of the queue
6. dequeueR(): Delete the rear element
7. dequeueF(): Delete the front element
8. print(): Print elements of the queue
39
40
Types of Dequeue
41
42
43
44
45
46
47
MULTIPLE QUEUE
PRESENTOR: JHON FERNAND BAUNO
55
56
57
58
59
CASE STUDY
(JOSEPHUS PROBLEM)
PRESENTOR: MARY ANN MORI
60
PRESENTOR: JOVIE NINA
ARRIESGADO
Claude GasparBachet de
Meziriac's interpretation of the
Josephus problem with 41
soldiers and a step size of 3,
showing that places 16 and 31
are last to be killed – time
progresses inwards along the
spiral, green dots denoting live
soldiers, grey dead soldiers,
and crosses killings
61
PRESENTOR:
GLAIZA
CARTAGENA
Example:
Input: N = 6, K = 2
Output: 5
62
Let's take an example of there are 5 people in a circle and execution starts
clockwise at position 3, so I will find out the winner of the game.
63
64
65
66