Data Structure MCQ - Queues
Q1.Following is C like pseudo code of a function that takes a Queue as an argument, and uses a stack S to do processing.
void fun(Queue *Q) { Stack S; // Say it creates an empty stack S // Run while Q is not empty while (!isEmpty(Q)) { // deQueue an item from Q and push the dequeued item to S push(&S, deQueue(Q)); } // Run while Stack S is not empty while (!isEmpty(&S)) { // Pop an item from S and enqueue the popped item to Q enQueue(Q, pop(&S)); } }What does the above function do in general?
- Removes the last from Q
- Keeps the Q same as it was before the call
- Makes Q empty
- Reverses the Q
Answer:- (D).
Explanations :The function takes a queue Q as an argument. It dequeues all items of Q and pushes them to a stack S. Then pops all items of S and enqueues the items back to Q. Since stack is LIFO order, all items of queue are reversed.
Explanations :The function takes a queue Q as an argument. It dequeues all items of Q and pushes them to a stack S. Then pops all items of S and enqueues the items back to Q. Since stack is LIFO order, all items of queue are reversed.
- When a resource is shared among multiple consumers
- When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes
- Load Balancing
- All of the above
Answer:- (D).
- 1
- 2
- 3
- 4
Answer:- (B).
Explanations :A stack can be implemented using two queues.
Explanations :A stack can be implemented using two queues.
- In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end.
- In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning.
- Both of the above
- None of the above
Answer:- (C).
Explanations :To keep the First In First Out order, a queue can be implemented using linked list in any of the given two ways.
Explanations :To keep the First In First Out order, a queue can be implemented using linked list in any of the given two ways.
- FIFO (First In First Out)
- LIFO (Last In First Out)
- Ordered array
- Linear tree
Answer:- (A).
Explanations :Element first added in queue will be deleted first which is FIFO principle.
Explanations :Element first added in queue will be deleted first which is FIFO principle.
- Square Buffer
- Ring Buffer
- Rectangle Buffer
- Curve Buffer
Answer:- (B).
Explanations :Circular Queue is also called as Ring Buffer. Circular Queue is a linear data structure in which last position is connected back to the first position to make a circle. It forms a ring structure.
Explanations :Circular Queue is also called as Ring Buffer. Circular Queue is a linear data structure in which last position is connected back to the first position to make a circle. It forms a ring structure.
- Ordinary queue
- Single ended queue
- Circular queue
- Priority queue
Answer:- (B).
- A queue cannot be implemented using this stack.
- A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE takes a sequence of two instructions.
- A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.
- A queue can be implemented where both ENQUEUE and DEQUEUE take a single instruction each.
Answer:- (C).
Explanations :To DEQUEUE an item, simply POP. To ENQUEUE an item, we can do following 3 operations 1) REVERSE 2) PUSH 3) REVERSE.
Explanations :To DEQUEUE an item, simply POP. To ENQUEUE an item, we can do following 3 operations 1) REVERSE 2) PUSH 3) REVERSE.
- ABCD
- DCBA
- DCAB
- ABCD
Answer:- (A).
Explanations :Because Queue follow FIFO rule.
Explanations :Because Queue follow FIFO rule.
- rear=(rear%1)+MAX_SIZE
- rear=rear%(MAX_SIZE+1)
- rear=(rear+1)%MAX_SIZE
- rear=rear+(1%MAX_SIZE)
Answer:- (C).
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.