0% found this document useful (0 votes)
61 views

QUEUES Docs

This document provides an agenda for a group presentation on queues. It lists the presenters and assigned topics which include introductions to queues, linked representation of queues, circular queues, priority queues, dequeues, multiple queues, and a case study on the Josephus problem. For each topic, it provides a brief overview and outlines what will be covered in the associated presentation.

Uploaded by

GLAIZA CARTAGENA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

QUEUES Docs

This document provides an agenda for a group presentation on queues. It lists the presenters and assigned topics which include introductions to queues, linked representation of queues, circular queues, priority queues, dequeues, multiple queues, and a case study on the Josephus problem. For each topic, it provides a brief overview and outlines what will be covered in the associated presentation.

Uploaded by

GLAIZA CARTAGENA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

QUEUES

              GROUP 4 PRESENTORS

GLENNIE ROSE DOBLE       KIZZEL NOYNAY


DAREN JOY BITOS          NOELYN MICARSOS
MARY ANN MORI            GLAIZA CARTAGENA
JOHN FERNAND BAUNO       JOVIE NINA ARRIESGADO
ASSIGNED Introduction to Linked Circular
TOPICS Queues Representation Queues
of Queues

Case Study(
Dequeues Priority Queue Multiple Queue Josephus
Problem)

2
INTRODUCTION  TO QUEUES
                    PRESENTOR: GLAIZA A. CARTAGENA

What is Queue?

Queue in C is a versatile and data structure in C which


overcomes the problems of insertion and deletion of elements
whether from the front end or rear end. Moreover, it has the
capability of determining the operations in a way that they can
be enqueued and dequeued in any way. Unlike stack, it is being
used in First in First Out [FIFO] order.

3
Analogy For Queue

You are visiting a doctor for a check-up. There are many


people at the clinic. A lady is entering the names of all the
people in a file. The person who comes first gets places first.
When the doctor is free, he calls the first patient inside. This
is a queue and follows a first in first out method as the first
person to enter his name in the list gets treated first.
The people who are treated their names are removed from the
list. This is how a queue works.
There are 2 pointers, the front is at the front of the queue and
rear is at the back of the queue. We add elements from the
back of the queue and remove them from the front of the 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 disadvantage of using an array to represent a queue is that


the array must be specified to have a fixed size. If the array size
cannot be known ahead of time, then the linked representation is
used.

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

As its name suggests a priority queue is a kind of queue that will


be assigned a priority to the elements needed to be inserted or
deleted.

Assignment of rules are as follows:

• An element inserted with higher priority will be processed first


and then with the lower priority.
• Two elements being added simultaneously will get the priority in
an order in which they are added simultaneously.

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. 

Types of Priority Queue


•Min Priority Queue: In the min priority Queue a minimum number of values
gets the highest priority and the lowest number of elements gets the highest
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

• Input Restricted Dequeue


• Output Restricted Dequeue

In Input Restricted Dequeue , insertion can be done from REAR only,


but deletion can be done from both FRONT and REAR.
In Output Restricted Dequeue, deletion can be done from FRONT
only, but insertion can be done from both FRONT and REAR.

41
42
43
44
45
46
47
MULTIPLE QUEUE
PRESENTOR: JHON FERNAND BAUNO

Each algorithm supports a different process, but in a general


system, some processes require scheduling using a priority
algorithm. While some processes want to stay in the
system (interactive processes), others are background
processes whose execution can be delayed.
A round-robin method with various time quantum is typically
utilized for such maintenance. Several types of scheduling
algorithms are designed for circumstances where the processes
can be readily separated into groups. There are two sorts of
processes that require different scheduling algorithms because
they have varying response times and resource requirements. The
foreground (interactive) and background processes (batch process)
are distinguished. Background processes take priority over
foreground processes. 48
49
50
51
52
53
54
PRESENTATION TITLE

55
56
57
58
59
CASE STUDY
(JOSEPHUS PROBLEM)
PRESENTOR: MARY ANN MORI

The problem is named after Flavius Josephus, a Jewish historian


living in the 1st century. According to Josephus' account of
the siege of Yodfat, he and his 40 soldiers were trapped in a cave
by Roman soldiers. They chose suicide over capture, and settled on
a serial method of committing suicide by drawing lots. Josephus
states that by luck or possibly by the hand of God, he and another
man remained until the end and surrendered to the Romans
rather than killing themselves. 

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.

So there are five people – 1 2 3 4 5 and execution starts clockwise at position


3. Therefore if you kill 3 then are left with the list something like – 1 2 4 5.
Now again, you want to kill the person at position 3 clockwise counting from
the last killed person.
Now, you need to execute the person at position 1. So executing the person at 1,
you are left with the list 2 4 5. After executing another person, you get list 2
4.
Now, you are left with 2 persons in the list. So, you have to calculate the
position wisely to execute the person.
So finally the winner is 4.

63
64
65
66

You might also like