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

Meloi M. Magpantay It2A: Unleashin

1) Queues and stacks are both linear data structures that can add elements one at a time, but they differ in processing order. Queues follow FIFO processing with insertion at the rear and deletion at the front, while stacks follow LIFO processing with push/pop at one end. 2) Queues can be represented using arrays or linked lists. Array representations use front and rear pointers, while linked list representations use front and rear pointers linking the nodes. 3) Common queue types include simple queues, circular queues, priority queues, and double-ended queues. Real-life applications of queues include CPU and disk scheduling, print spooling, graph searching, and call center phone systems.

Uploaded by

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

Meloi M. Magpantay It2A: Unleashin

1) Queues and stacks are both linear data structures that can add elements one at a time, but they differ in processing order. Queues follow FIFO processing with insertion at the rear and deletion at the front, while stacks follow LIFO processing with push/pop at one end. 2) Queues can be represented using arrays or linked lists. Array representations use front and rear pointers, while linked list representations use front and rear pointers linking the nodes. 3) Common queue types include simple queues, circular queues, priority queues, and double-ended queues. Real-life applications of queues include CPU and disk scheduling, print spooling, graph searching, and call center phone systems.

Uploaded by

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

CI TE

2.0
U n le a s h in

Meloi M. Magpantay
IT2A

1. Define queues. Discuss its similarities and differences over stacks.


A Queue is a linear structure which follows a particular order in which the operations
are performed. The order is First In First Out (FIFO)..
Similarities:
 Queues and Stacks are both an abstract data type
 Can both add item the last position
 Can add one element at a time
 Are both linear structure
Differences:
Stacks Queues
Follows First in Last Out (FILO) Follows First in First Out (FIFO)
Open at both ends Insertion and deletion takes place at the
same end
The object can be removed which is add The object which is added first can only be
last removed from the queue

Push adds items to the stack and pop Enqueue adds items to the rear and
removes recently added items from the dequeue removes items from the front of
stack the queue
Only one pointer is used in a stack Two pointers are used in simple queue
case

2. Discuss the two representations/implementations of queues using arrays


and linked lists.

Array
We can easily represent queue by using linear arrays. There are two variables
i.e. front and rear, that are implemented in the case of every queue. Front and rear
variables point to the position from where insertions and deletions are performed in a
queue. Initially, the value of front and queue is -1 which represents an empty queue.
CI TE

2.0
U n le a s h in

Array representation of a queue containing 5 elements along with the respective values
of front and rear, is shown in the following figure.

The above figure shows the queue of characters forming the English word
"HELLO". Since, No deletion is performed in the queue till now, therefore the value of
front remains -1 . However, the value of rear increases by one every time an insertion is
performed in the queue. After inserting an element into the queue shown in the above
figure, the queue will look something like following. The value of rear will become 5
while the value of front remains same.

After deleting an element, the value of front will increase from -1 to 0. however,
the queue will look something like following.
CI TE

2.0
U n le a s h in

Linked List
In a linked queue, each node of the queue consists of two parts i.e. data part and
the link part. Each element of the queue points to its immediate next element in the
memory.
In the linked queue, there are two pointers maintained in the memory i.e. front
pointer and rear pointer. The front pointer contains the address of the starting element
of the queue while the rear pointer contains the address of the last element of the
queue.
Insertion and deletions are performed at rear and front end respectively. If front
and rear both are NULL, it indicates that the queue is empty.
The linked representation of queue is shown in the following figure.
CI TE

2.0
U n le a s h in

3. Enumerate and discuss the types of queues.


Simple Queue

Simple queue lets us perform the operations simply. i.e., the insertion and
deletions are performed likewise. Insertion occurs at the rear (end) of the queue and
deletions are performed at the front (beginning) of the queue list.
All nodes are connected to each other in a sequential manner. The pointer of the
first node points to the value of the second and so on.
The first node has no pointer pointing towards it whereas the last node has no
pointer pointing out from it.

Circular Queue

In a circular queue each node is connected to the next node in sequence but the
last node’s pointer is also connected to the first node’s address. Hence, the last node
and the first node also gets connected making a circular link overall.
CI TE

2.0
U n le a s h in

Priority Queue

Priority queue makes data retrieval possible only through a pre determined
priority number assigned to the data items.
While the deletion is performed in accordance to priority number (the data item
with highest priority is removed first), insertion is performed only in the order.

Doubly Ended Queue (Dequeue)


CI TE

2.0
U n le a s h in

The doubly ended queue or dequeue allows the insert and delete operations
from both ends (front and rear) of the queue.
Queues are an important concept of the data structures and understanding their
types is very necessary for working appropriately with them.

4. Discuss the operations of queues.


Queue operations may involve initializing or defining the queue, utilizing it, and then
completely erasing it from the memory.
 Traversal- This is the process of accessing each and every element of the
queue.
 Enqueue- This is an operation where you can add an element to the end of the
queue.
 Dequeue- This is an operation where you can delete an element from the starting
of the queue.
 Searching- You can search through the queue for an element of your choice and
display it's position in the queue.
 Merging- You can merge two queues together, one behind the other.

5. Enumerate 3 applications of queues in real life and in the field of Computer


Science.
 Queue is useful in CPU scheduling, Disk Scheduling. When multiple processes
require CPU at the same time, various CPU scheduling algorithms are used
which are implemented using Queue data structure.
 When data is transferred asynchronously between two processes. Queue is used
for synchronization. Examples : IO Buffers, pipes, file IO, etc.
 In print spooling, documents are loaded into a buffer and then the printer pulls
them off the buffer at its own rate. Spooling also lets you place a number of print
jobs on a queue instead of waiting for each one to finish before specifying the
next one.
 Breadth First search in a Graph .It is an algorithm for traversing or searching
graph data structures. It starts at some arbitrary node of a graph and explores
the neighbor nodes first, before moving to the next level neighbors.This Algorithm
uses Queue data structure.
CI TE

2.0
U n le a s h in

 Handling of interrupts in real-time systems. The interrupts are handled in the


same order as they arrive, First come first served.
 In real life, Call Center phone systems will use Queues, to hold people calling
them in an order, until a service representative is free.

References:
https://www.geeksforgeeks.org/queue-data-structure/
CI TE

2.0
U n le a s h in

https://www.google.com/search?
q=similarities+and+differences+of+queues+and+stacks&tbm=isch&source=iu&ictx=1&fi
r=XpR-UuXteam9gM%253A%252CfGFZCb3cc9XqYM%252C_&vet=1&usg=AI4_-
kQUDYUJdlAiJt7JO_c9tla18LIoRQ&sa=X&ved=2ahUKEwjSor3FkPXlAhUFy4sBHarOC
LwQ9QEwAHoECAUQAw#imgrc=XpR-UuXteam9gM:
https://www.google.com/search?
q=similarities+and+differences+of+queues+and+stacks&oq=similarities+and+difference
s+of+queues+and+stacks&aqs=chrome..69i57j0l2.11736j1j7&sourceid=chrome&ie=UT
F-8
https://www.javatpoint.com/array-representation-of-queue
https://www.geeksforgeeks.org/queue-linked-list-implementation/
https://www.thecrazyprogrammer.com/2019/01/types-of-queues-in-data-structure.html
https://www.quora.com/What-are-the-applications-of-queues
https://www.quora.com/What-are-the-various-operations-in-a-queue-Can-you-explain-
each-of-them
https://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm

You might also like