You are on page 1of 5

CI TE

2.0
U nle a shing Possibilit ie s

Homework #5 (HW5): Types of Queues


Data Structures and Algorithms

Vergara, Aaron Charles C2A

Answer the following questions:

1. What is a circular queue? Describe how it differs from an ordinary queue.


A circular queue is a data structure that utilizes a single, fixed-size buffer in which
the last position is connected to the first position of the queue to make a circle. Table 1
below displays the characteristics of an ordinary linear queue and a circular queue and
how they differ.

Ordinary Linear Queue Circular Queue

Stores data as a sequence of elements like a The last item of the data connects back to
real-world queue the first item, creating a circle
Possible to enter new items through the rear, Possible to enter and remove items from
and remove items through the front any position of the queue
Requires more memory Requires less memory
Less efficient More efficient

Table 1. Ordinary Linear Queue and Circular Queue Comparison


CI TE

2.0
U nle a shing Possibilit ie s

2. Enumerate at least two real life applications of circular queue.


An airport baggage carousel is one example of a circular queue in real life, as
baggage enters at the rear of the carousel line, in which people can just pick up their own
stuff at random positions where it is located, like how its possible to remove elements
from any position in a circular queue.

The Congo Line Dance is also one example where circular queueing can be seen
in performance action, as people enter from the rear end of the circular queue but can
exit from the front or randomly.

Both examples can be considered imperfect circular queue as in reality, they don’t
fully follow the same consistent exit through the front of the queue. But with the right
situations or conditions, they do function as such, where members of the queue exit right
at the front of the queue.
CI TE

2.0
U nle a shing Possibilit ie s

3. What is a priority queue? Describe how it differs from an ordinary queue.

A priority queue is an abstract data type comparable to a queue data structure, in


which instead of following a FIFO sequence order, stacks and acts on elements in terms
of the priority value assigned to it. Table 2 below displays the characteristics of an
ordinary linear queue and a priority queue and how they differ or be similar in some ways.

Ordinary Linear Queue Priority Queue

Stores data as a sequence of elements like a Stores data with regards to the priority
real-world queue value of the element
Possible to enter new items through the rear, Insertion and removal don’t happen at a
and remove items through the front specific end, it happens through priority
choice
Elements stay at the same FIFO order Elements are re-ordered to make the front
whenever an element is pushed onto the of the queue contain the element with the
back or popped off the front smallest or largest value depending on
order priority
Popping out elements follow the FIFO Popping out elements always come out in
(First In First Out) order either ascending or descending order
Requires more memory compared to circular queue
Less efficient than circular queue

Table 2. Ordinary Linear Queue and Priority Queue Comparison


CI TE

2.0
U nle a shing Possibilit ie s

4. Enumerate at least two real life applications of a priority queue.

A hospital applies priority queue during emergencies, whether there are sudden
appearance of patient/s who need immediate assistance. From such, prioritized patients
are immediately assisted first to the emergency room over other patients with less
priority concerns.

Traffic lights apply priority queues on the colors it is supposed to show, depending
on the traffic situation. One prioritization example that a traffic signal can perform is
extending relative green time depending on the flow of mixed traffic on the crossing
street, particularly on times where there is a significant amount of pedestrian flow
compared to vehicle flow in a specific time.
CI TE

2.0
U nle a shing Possibilit ie s

5. Your references.

• Geeks for Geeks. (2020). Difference between Circular Queue and Priority Queue. Retrieved from
https://www.geeksforgeeks.org/difference-between-circular-queue-and-priority-queue/?ref=rp
• Lithmee. (2019). What is the Difference Between Linear Queue and Circular Queue. Retrieved
from https://pediaa.com/what-is-the-difference-between-linear-queue-and-circular-queue/
• Stack Overflow. (2016). What is a real lif e example of a ring buffer/circular queue. Retrieved
from https://stackoverflow.com/questions/40203296/what-is-a-real-life-example-of-a-ring-
buffer-circular-queue

You might also like