Professional Documents
Culture Documents
Stack ADT
Queue ADT
1. It is an ordered list where insertion and 1. It is an ordered collection of element where
deletion operation are performed at one end
insertion operation is performed at rear end
called Top of stack.
and deletion operation is performed at front
end of queue.
2. Stack is based on LIFO logic.
2. Queue is based on FIFO logic.
3. Associated with stack there is one variable 3. Associated with queue there are two
called Top.
variable named as front and rear.
4. Insertion & deletion operations are referred
4. Insertion and deletion operations are
as Enqueue & Dequeue respectively.
referred as PUSH & POP respectively.
5. Fully occupied queue is identified by rear =
5. Fully occupied stack can be identified by
= Qsize-1
Top = =Stacksize-1
6. To insert an element rear is incremented by
6. To insert an element Top is incremented by
one.
one.
7. To delete an element front is incremented
7. To delete an element Top is decremented
by one.
by one.
13. What is a constraint for fully loaded queue and empty queue?
If the number of elements stored onto the queue is equal to the queue size then the
queue is called as Fully Occupied Queue (i.e.) Rear < (Qsize 1)
If there is no element in queue then it is called as Empty Queue (i.e.) Front= = -1
14. Define linear queue and its demerits.
It is a simple queue structure. Linear queue is mostly implemented by using Array
Data Structure.
During the enqueue operation, the rear variable is incremented by one and new
element is placed on the rear position of queue.
During the Dequeue operation, the front variable is incremented by one.
Demerits
In linear queue, the Enqueue operation is performed irrespective of the position of
front variable that is after the deletion of some elements from the queue, it wont be
fully occupied queue but we cant perform Enqueue of new element onto the queue.
So the Queue size is not properly utilized i.e. memory is wasted.
15. Define circular queue with neat sketch.
It is same as linear queue except that the structure of queue becomes circularly
connected. So that, the memory space of dequeued element is also used for enqueue
until the queue is full.
To insert element, the rear pointer is incremented by one and the new element is
stored on the position [rear % Qsize]. During the Dequeue operation, the front
variable is incremented by one.
Qsizewhen
= 8 difference of rear and front is equal to
The queue is said to be fully occupied
the queue size minus one (rear-front= =Qsize-1).
1
Front = 0
0
START of QUEUE
2
3
4
Rear = 4
Front
Deletio
n
..
Input-Restricted
Deque
Rear
Front
Deletio
n
..
Deletio
n
Insertio
n
Output-Restricted
Deque
Linear Queue
Circular Queue
Empty
queue
Enqueu
e
Linear Queue
Circular Queue
Linear Queue
Circular Queue