CDS Q9
CDS Q9
CDS Q9
1. A linear list of elements in which deletion can be done from one end (front) and insertion can
take place only at the other end (rear) is known as a ?
2. The data structure required for Breadth First Traversal on a graph is?
3. Let the following circular queue can accommodate maximum six elements with the following
data:
front = 2 rear = 4
queue = _______; L, M, N, ___, ___
4. A queue is a ?
(a) FIFO (First In First Out) list (b) LIFO (Last In First Out) list
(c) Ordered array (d) Linear tree
5. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in
what order will they be removed?
1
6. In linked list implementation of a queue, where does a new element be inserted?
(b) A queue can be implemented where ENQUEUE takes a single instruction and DEQUEUE
takes a sequence of two instructions.
(c) A queue can be implemented where ENQUEUE takes a sequence of three instructions and
DEQUEUE takes a single instruction.
(d) A queue can be implemented where both ENQUEUE and DEQUEUE take a single
instruction each.
8. Following is C like pseudo code of a function that takes a Queue as an argument, and uses a
stack S to do processing.
2
{
// Pop an item from S and enqueue the poppped item to Q
enQueue(Q, pop(&S));
}
}
10. How many stacks are needed to implement a queue. Consider the situation where no other
data structure like arrays, linked list is available to you.
(a) 1 (b) 2
(c) 3 (d) 4
11. How many queues are needed to implement a stack. Consider the situation where no other
data structure like arrays, linked list is available to you.
(a) 1 (b) 2
(c) 3 (d) 4
12. Which of the following is true about linked list implementation of queue?
3
(a) In push operation, if new nodes are inserted at the beginning of linked list, then in pop
operation, nodes must be removed from end.
(b) In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be
14. An implementation of a queue Q, using two stacks S1 and S2, is given below:
void insert(Q, x) {
push (S1, x);
}
void delete(Q){
if(stack-empty(S2)) then
if(stack-empty(S1)) then {
print(“Q is empty”);
return;
}
else while (!(stack-empty(S1))){
x=pop(S1);
push(S2,x);
}
x=pop(S2);
}
4
Let n insert and m (<=n) delete operations be performed in an arbitrary order on an empty queue
Q . Let x and y be the number of push and pop operations performed respectively in the process.
Which one of the following is true for all m and n?
15. Consider the following operation along with Enqueue and Dequeue operations on queues,
where k is a global parameter.
MultiDequeue(Q){
m=k
while (Q is not empty and m > 0) {
Dequeue(Q)
m=m-1
}
}
What is the worst case time complexity of a sequence of n MultiDequeue() operations on an
initially empty queue? (GATE CS 2013)
16. Consider the following pseudo code. Assume that IntQueue is an integer queue. What does
the function fun do?
void fun(int n)
{
IntQueue q = new IntQueue();
q.enqueue(0);
q.enqueue(1);
for (int i = 0; i < n; i++)
{
int a = q.dequeue();
int b = q.dequeue();
q.enqueue(b);
5
q.enqueue(a + b);
print(a);
}
}
17. A circular queue is implemented using an array of size 10. The array index starts with 0,
front is 6, and rear is 9. The insertion of next element takes place at the array index.
(a) 0 (b) 7
(c) 9 (d) 10