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

Stack Queue: F I F O

Queue is a linear data structure that follows a first-in, first-out (FIFO) ordering principle. Items are added to the rear of the queue and removed from the front. Main operations on a queue are enqueue, which adds an item, dequeue, which removes an item, and operations to access the front and rear items. Queue is useful when items don't need immediate processing but must be processed in the order they are received, such as in breadth-first search algorithms.

Uploaded by

Sameer Memon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Stack Queue: F I F O

Queue is a linear data structure that follows a first-in, first-out (FIFO) ordering principle. Items are added to the rear of the queue and removed from the front. Main operations on a queue are enqueue, which adds an item, dequeue, which removes an item, and operations to access the front and rear items. Queue is useful when items don't need immediate processing but must be processed in the order they are received, such as in breadth-first search algorithms.

Uploaded by

Sameer Memon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Like Stack, Queue is a linear structure which follows a particular order in which the

operations are performed. The order is First In First Out (FIFO).


The difference between stacks and queues is in removing. In a stack we remove the
item the most recently added; in a queue, we remove the item the least recently added.
Operations on Queue:
Mainly the following four basic operations are performed on queue:

Enqueue: Adds an item to the queue. If the queue is full, then it is said to be an Overflow condition.
Dequeue: Removes an item from the queue. The items are popped in the same order in which they
are pushed. If the queue is empty, then it is said to be an Underflow condition.
Front: Get the front item from queue.
Rear: Get the last item from queue.

Queue is used when things dont have to be processed immediatly, but have to be processed
in First InFirst Out order like Breadth First Search.

Breadth first search does the search for nodes level-by-level, i.e. it searches the nodes with respect
to their distance from the root.

Array implementation Of Queue


For implementing queue, we need to keep track of two indices, front and rear. We enqueue an item
at the rear and dequeue an item from front. If we simply increment front and rear indices, then
there may be problems, front may reach end of the array. The solution to this problem is to increase
front and rear in circular manner (See this for details)

You might also like