The LIFO stands for Last In First Out. This property belongs to stack. That means the element inserted lastly will be the element to be popped off first from the stack.
Two Marks Questions with Answers
Q.1 What do the terms LIFO and FIFO means?
Explain.
Ans. : The LIFO stands for Last
In First Out. This property belongs to stack. That means the element inserted
lastly will be the element to be popped off first from the stack.
The FIFO
stands for First In First Out. This property belongs to queue. That means the
element inserted first in the queue will be the first to get deleted.
Q.2 What are the front and rear pointers of
queue.
Ans. : The front end of the
queue from which the element gets deleted is called front and the end from
which the element is inserted in the queue is called rear.
For
example: Refer Fig.
Q.3 What is a circular queue?
Ans. : Circular queue is a queue in
which the front end is just adjacent to the rear end. The elements get arranged
in circular manner. For example - Refer Fig.
Q.4 Write any four applications of queues.
Ans;
1. In
operating system for scheduling jobs, priority queues are used.
2. In
Local Area Network (LAN) multiple computers share few printers. Then these
printers accumulate jobs in a queue. Thus printers can process multiple print
commands with the help of queues.
3. For
categorizing data, queues are used.
4. In
simulation and modeling queues are used.
5. In
computer networks, while broadcasting message, the message packets are
accumulated in queue. And then these packets are forwarded.
Q.5 What is a dequeue?
Ans. : The dequeue is a data
structure in which the element can be inserted from both the ends i.e. front
and rear. Similarly, the element can be deleted from both the front and rear
end.
Q.6 How do you test for an empty queue?
Ans. Following is a C code which
is used to test an empty queue
if((Q.front==-1)
| | (Q.front>Q.rear))
printf("\n
The Queue is Empty!!");
else
printf("\n
The Queue is not Empty!!")
Q.7 What is the use of queue in operating
system?
Ans. : The queue is used for
scheduling the jobs in operating system.
Q.8What is the need for circular queue ?
Ans.
The
circular queue is an useful data structure in which all the cells of the queue
can be utilized. Secondly due to circular queue one can traverse to the first
node from the last node very efficiently.
Q.9 What is stack and Queue ?
Ans. : Stack is linear data structure
in which insertion and deletion of element is from one end called top.
Queue is
a linear data structure in which insertion of element is from one end called
rear and deletion of element is from other end called front.
Q.10 What are priority queues? What are the
ways to implement priority queue ?
Ans.
Definition:
The priority queue is a data structure having a collection of elements which
are associated with specific ordering.
•Ways to implement Priority Queue:
There
are two ways to implement priority queue.
1. Ascending Priority Queue - It is
a collection of items in which the items can be inserted arbitarily but only
smallest element can be removed.
2. Descending Priority Queue - It is
a collection of items in which insertion of items can be in any order but only
largest element can be removed.
Q.11 A priority queue is impletemented as Max
heap. Initially it has 5 elements. The level order traversal of heap is: 10, 8,
5, 3, 2. Two new elements 11 and 7 are inserted into the heap in that order.
Give level order traversal of the heap after the insertion of elements.
Ans.
Step 1: The heap is as shown below.
Step 2: The level order after insertion of given elements is 11, 8, 10,
3, 2, 7.
Data Structure: Unit II (b): Queue : Tag: : Queue ADT | Data Structure - Two marks Questions with Answers
Data Structure
CS3301 3rd Semester CSE Dept | 2021 Regulation | 3rd Semester CSE Dept 2021 Regulation