GATE Level MCQS
UNIT-III
PREPARED BY:
MEHAK(23837)
SEEE-CSE
1. Assume that the operators +, -, × are left associative and ^ is right
associative. The order of precedence (from highest to lowest) is ^, x
, +, -. The postfix expression corresponding to the infix expression a +
b × c - d ^ e ^ f is_________________
A. abc × + def ^ ^ -
B. abc × + de ^ f ^ -
C. ab + c × d - e ^ f ^
D. - + a × bc ^ ^ def
1. Assume that the operators +, -, × are left associative and ^ is right
associative. The order of precedence (from highest to lowest) is ^, x
, +, -. The postfix expression corresponding to the infix expression a +
b × c - d ^ e ^ f is_________________
A. abc × + def ^ ^ -
B. abc × + de ^ f ^ -
C. ab + c × d - e ^ f ^
D. - + a × bc ^ ^ def
2. The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is…..
A. 284
B. 213
C. 142
D. 71
2. The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is…..
A. 284
B. 213
C. 142
D. 71
3. Consider n elements that are equally distributed in k stacks. In
each stack, elements of it are arranged in ascending order (min is
at the top in each of the stack and then increasing downwards).
Given a queue of size n in which we have to put all n elements in
increasing order. What will be the time complexity of the best
known algorithm?
A. O(n logk)
B. O(nk)
C. O(n2)
D. O(k2)
3. Consider n elements that are equally distributed in k stacks. In
each stack, elements of it are arranged in ascending order (min is
at the top in each of the stack and then increasing downwards).
Given a queue of size n in which we have to put all n elements in
increasing order. What will be the time complexity of the best
known algorithm?
A. O(n logk) In nlogk it can be done by creating a min heap of size k and adding
all the top - elements of all the stacks. After extracting the min , add
B. O(nk) the next element from the stack from which we have got our 1st
minimum.
C. O(n2) Time Complexity = O(k) (For Creating Heap of size k) + (n-k)log k
D. O(k2) (Insertions into the heap).
4. Consider the following statements:
i. First-in-first out types of computations are efficiently supported by
STACKS.
ii. Implementing LISTS on linked lists is more efficient than implementing
LISTS on an array for almost all the basic LIST operations.
iii. Implementing QUEUES on a circular array is more efficient than
implementing QUEUES on a linear array with two indices.
iv. Last-in-first-out type of computations are efficiently supported by
QUEUES.
Which of the following is correct?
A. (ii) and (iii) are true
B. (i) and (ii) are true
C. (iii) and (iv) are true
D. (ii) and (iv) are true
4. Consider the following statements:
i. First-in-first out types of computations are efficiently supported by
STACKS.
ii. Implementing LISTS on linked lists is more efficient than implementing
LISTS on an array for almost all the basic LIST operations.
iii. Implementing QUEUES on a circular array is more efficient than
implementing QUEUES on a linear array with two indices.
iv. Last-in-first-out type of computations are efficiently supported by
QUEUES.
Which of the following is correct?
A. (ii) and (iii) are true
B. (i) and (ii) are true
C. (iii) and (iv) are true
D. (ii) and (iv) are true
5. The minimum number of stacks needed to implement a queue is
A. 3
B. 1
C. 2
D. 4
5. The minimum number of stacks needed to implement a queue is
A. 3
B. 1
C. 2
D. 4
6. Which of the following is not an inherent application of stack?
A. Implementation of recursion
B. Evaluation of a postfix expression
C. Job scheduling
D. Reverse a string
6. Which of the following is not an inherent application of stack?
A. Implementation of recursion
B. Evaluation of a postfix expression
C. Job scheduling
D. Reverse a string
7. Stack A has the entries a, b, c (with a on top). Stack B is empty.
An entry popped out of stack A can be printed immediately or
pushed to stack B. An entry popped out of the stack B can be only
be printed. In this arrangement, which of the following permutations
of a, b, c are not possible?
A. b a c
B. b c a
C. c a b
D. a b c
7. Stack A has the entries a, b, c (with a on top). Stack B is empty.
An entry popped out of stack A can be printed immediately or
pushed to stack B. An entry popped out of the stack B can be only
be printed. In this arrangement, which of the following permutations
of a, b, c are not possible?
A. b a c
B. b c a
C. c a b
D. a b c
Option (A):
Pop a from stack A
Push a to stack B
Print b
Print a from stack B Option (C):
Pop a from stack A
Print c from stack A Push a to stack B
Order = b a c Pop b from stack A
Push b to stack B
Print c from stack A
Now, printing a will not be possible.
Option (B):
So, option (C) is incorrect.
Pop a from stack A
Push a to stack B
Print b from stack A
Print c from stack A
Print a from stack A
Order = b c a
8. 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
8. 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
9. Which of the following is true about linked list implementation of
queue?
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 removed from the beginning.
C. Both of the above
D. None of the above
9. Which of the following is true about linked list implementation of
queue?
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 removed from the beginning.
C. Both of the above To keep the First In First Out order, a queue can be
D. None of the above implemented using linked list in any of the given two
ways.
10. A queue is implemented using a non-circular singly linked list. The
queue has a head pointer and a tail pointer, as shown in the figure. Let n
denote the number of nodes in the queue. Let 'enqueue' be
implemented by inserting a new node at the head, and 'dequeue' be
implemented by deletion of a node from the tail.
Which one of the following is the time complexity of the most time-
efficient implementation of 'enqueue' and 'dequeue, respectively, for this
data structure?
A. Θ(1), Θ(1)
B. Θ(1), Θ(n)
C. Θ(n), Θ(1)
D. Θ(n), Θ(n)
10. A queue is implemented using a non-circular singly linked list. The
queue has a head pointer and a tail pointer, as shown in the figure. Let n
denote the number of nodes in the queue. Let 'enqueue' be
implemented by inserting a new node at the head, and 'dequeue' be
implemented by deletion of a node from the tail.
Which one of the following is the time complexity of the most time-
efficient implementation of 'enqueue' and 'dequeue, respectively, for this
data structure?
A. Θ(1), Θ(1)
B. Θ(1), Θ(n)
C. Θ(n), Θ(1)
D. Θ(n), Θ(n)
For Enqueue operation, performs in constant amount of time (i.e., Θ(1)), because it modifies
only two pointers, i.e.,
Create a Node P.
P-->Data = Data
P-->Next = Head
Head = P
For Dequeue operation, we need address of second last node of single linked list to make NULL
of its next pointer. Since we can not access its previous node in singly linked list, so need to
traverse entire linked list to get second last node of linked list, i.e.,
temp = head;
While( temp-Next-->Next != NULL){
temp = temp-Next;
}
temp-->next = NULL;
Tail = temp;
Since, we are traversing entire linked for each Dequeue, so time complexity will be Θ(n). Option
(B) is correct.