MCQ on stack and queue data structure. Both Stack and Queue data structure is very important in computer science. In this tutorial, you are going to learn about stack and queue data structure. Also you’ll find MCQ on stack and queues.
In my previous post, i have discussed how to implement stack and queue data structure.
Stack program in C using Array.
Queue data structure and their implementation.
The purpose of this objective questions is to test how well you understand the concept of stack and queue.
Stack vs Queue
1. Stack and Queue both are linear data structure. In Stack insertions and deletions are allowed only at one end. The element which we inserted at last is the first element to be popped out that is why it also called as LIFO (Last In First Out) data structure.
In queue insertion are performed on one end (Rear) and deletion is performed on other end (Front). The element which we enqueued first is the first element to be dequeued from the queue. That’s why it also known as FIFO (First In First Out) data structure. So, Queue uses FIFO principle.
2. In Stack, insertion operation is known as Push whereas deletion operation is known as Pop.
In queue, insertion operation is known as Enqueue whereas deletion operation is known as Dequeue.
Insertion and deletion operation in queue is known as enqueue and dequeue.
Application of Stack Data Structure
a) In recursive function.
b) This data structure is used internally in function calls.
c) Expression conversion such as – Infix to Postfix ,Infix to Prefix, Postfix to Infix,Prefix to Infix.
Application of Queue Data Structure
Queue are mostly used in an application when things doesn’t have to be process immediately. But they have to be processed in First In First Out order.
1) Queues are used in message broker such as Kafka, RabbitMQ etc. In these message brokers, the producer publish the message in a queue and consumers consume those messages in First In First Out order.
2) Serving requests of a single shared resource (printer, disk, CPU).
3) Transferring data asynchronously (data not necessarily received at same rate as sent) between two processes (IO buffers), e.g., pipes, file IO, sockets.
4) In consumer producer problem. When a resource is shared among multiple consumers. Examples include CPU scheduling, Disk Scheduling.
This is the general question asked in exams or in interviews.
* Which of the following can be used to implement stack?
i) Array
ii) Linked List
iii) Tree
iv)Graph
Stack can be implemented using array and linked list.
* The process of adding/inserting a new data element in a stack is known as push. The process of deleting/removing a new data element from the stack is known as pop.
* Which statement is correct with respect to stack?
1) It is a non-linear data structure.
2) Stack is a LIFO data structure
The correct answer is 2.
MCQ on Stack and Queue
1. The term Push and Pop is related to
a) Queue
b) Stack
c) Both
d) None
2. Choose correct output for the following sequence of operations.
1 2 3 4 5 6 7 8 9 10 |
push(5) push(8) pop push(2) push(5) pop pop pop push(1) pop |
a) 8 5 2 5 1
b) 8 5 5 2 1
c) 8 2 5 5 1
d) 8 1 2 5 5
3. In which data structure, element is inserted at one end called Rear and deleted at other end called Front.
a) Stack
b) Queue
c) Both
d) Binary Tree
4. Stack can be implemented using _________ and ________ ?
a) Array and Binary Tree
b) Linked List and Graph
c) Array and Linked List
d) Queue and Linked List
5. Postfix form of following expression.
D + (E * F)
a) EF * D+
b) DEF * +
c) DEF +*
d) EFD *+
6. When the function calls another function then the details of the previous function are stored in Stack?
a) True
b) False
7. Insertion and Deletion operation in Queue is known as?
a) Push and Pop
b) Enqueue and Dequeue
c) Insert and Delete
d) None
8. A stack data structure cannot be used for
a) Implementation of Recursive Function
b) Allocation Resources and Scheduling
c) Reversing string
d) Evaluation of string in postfix form
9. Which of the following principle does queue use?
a) LIFO
b) FIFO
c) Both
d) None of the above
10. The process of inserting an element in the stack is called?
a) Enqueue
b) Insert
c) Push
d) Pop
Answers
1) (b) In stack, push means inserting an element and pop means deleting an element.
Stack Implementation using array
2) (a)
3) (b) In queue element is inserted at one end called rear and deleted at other end called front.
Queue Implementation using array
4) (c)
5) (b)
6) (a)
7) (b)
8) (b) Queue data structure is used for allocating resources and scheduling.
9) (b) The queue uses FIFO (First-In-First-Out) principle. It means the element which inserted (enqueued) at first is the first element to be deleted (dequeued).
10) (c) The process of inserting a new element to the top of the stack is called push.
Programming video tutorial on stack.
Programming Questions on Stack – Video Tutorial