DS MCQ
DS MCQ
4. The data structure required to check whether an expression contains a balanced parenthesis is?
a) Queue
b) Stack
c) Tree
d) Array
View Answer
Answer: b
Explanation: The stack is a simple data structure in which elements are added and removed based on the LIFO principle. Open parenthesis
is pushed into the stack and a closed parenthesis pops out elements till the top element of the stack is its corresponding open parenthesis. If
the stack is empty, parenthesis is balanced otherwise it is unbalanced.
advertisement
6. Which data structure is needed to convert infix notation to postfix notation?
a) Tree
b) Branch
c) Stack
d) Queue
View Answer
Answer: c
Explanation: The Stack data structure is used to convert infix expression to postfix expression. The purpose of stack is to reverse the order of
the operators in the expression. It also serves as a storage structure, as no operator can be printed until both of its operands have appeared.
8. What data structure would you mostly likely see in non recursive implementation of a recursive algorithm?
a) Stack
b) Linked List
c) Tree
d) Queue
View Answer
Answer: a
Explanation: In recursive algorithms, the order in which the recursive process comes back is the reverse of the order in which it goes forward
during execution. The compiler uses the stack data structure to implement recursion. In the forwarding phase, the values of local variables,
parameters and the return address are pushed into the stack at each recursion level. In the backing-out phase, the stacked address is
popped and used to execute the rest of the code.
9. Which of the following statement(s) about stack data structure is/are NOT correct?
a) Top of the Stack always contain the new node
b) Stack is the FIFO data structure
c) Null link is present in the last node at the bottom of the stack
d) Linked List are used for implementing Stacks
View Answer
Answer: b
Explanation: Stack follows LIFO.
10. The data structure required for Breadth First Traversal on a graph is?
a) Array
b) Stack
c) Tree
d) Queue
View Answer
11. The prefix form of A-B/ (C * D ^ E) is?
a) -A/B*C^DE
b) -A/BC*^DE
c) -ABCD*^DE
d) -/*^ACBDE
View Answer
Answer: a
Explanation: Infix Expression is A-B/(C*D^E)
This can be written as: A-(B/(C*(D^E)))
Thus prefix expression is -A/B*C^DE.
12. Which of the following points is/are not true about Linked List data structure when it is compared with an array?
a) Random access is not allowed in a typical implementation of Linked Lists
b) Access of elements in linked list takes less time than compared to arrays
c) Arrays have better cache locality that can make them better in terms of performance
d) It is easy to insert and delete elements in Linked List
View Answer
Answer: b
Explanation: To access an element in a linked list, we need to traverse every element until we reach the desired element. This will take more
time than arrays as arrays provide random access to its elements.
13. Which data structure is based on the Last In First Out (LIFO) principle?
a) Tree
b) Linked List
c) Stack
d) Queue
View Answer
Answer: c
Explanation: The data structure that follows the Last In First Out (LIFO) principle is the Stack. It operates like a stack of objects, making it
suitable for specific-order management.
14. Which of the following application makes use of a circular linked list?
a) Recursive function calls
b) Undo operation in a text editor
c) Implement Hash Tables
d) Allocating CPU to resources
View Answer
Answer: d
Explanation: Generally, round robin fashion is employed to allocate CPU time to resources which makes use of the circular linked list data
structure. Recursive function calls use stack data structure. Undo Operation in text editor uses doubly linked lists. Hash tables uses singly
linked lists.
18. Which of the following data structures can be used for parentheses matching?
a) n-ary tree
b) queue
c) priority queue
d) stack
View Answer
Answer: d
Explanation: For every opening brace, push it into the stack, and for every closing brace, pop it off the stack. Do not take action for any other
character. In the end, if the stack is empty, then the input has balanced parentheses.
21. Which of the following is the most widely used external memory data structure?
a) B-tree
b) Red-black tree
c) AVL tree
d) Both AVL tree and Red-black tree
View Answer
Answer: a
Explanation: In external memory, the data is transferred in form of blocks. These blocks have data valued and pointers. And B-tree can hold
both the data values and pointers. So B-tree is used as an external memory data structure.
for(i=0;i<len;i++)
push(str[i]); // pushes an element into stack
for(i=0;i<len;i++)
pop(); //pops an element from the stack
}
a) yrdnuof nas
b) foundry nas
c) sanfoundry
d) san foundry
View Answer
Answer: a
Explanation: First, the string ‘san foundry’ is pushed one by one into the stack.
When it is popped, the output will be as ‘yrdnuof nas’.
24. Which of the following data structure can provide efficient searching of the elements?
a) binary search tree
b) unordered lists
c) 2-3 tree
d) treap
View Answer
Answer: c
Explanation: The average case time for lookup in a binary search tree, treap and 2-3 tree is O(log n) and in unordered lists it is O(n). But in
the worst case, only the 2-3 trees perform lookup efficiently as it takes O(log n), while others take O(n).
26. What is the time complexity for searching a key or integer in Van Emde Boas data structure?
a) O (M!)
b) O (log M!)
c) O (log (log M))
d) O (M2)
View Answer
Answer: c
Explanation: In order to search a key or integer in the Van Emde Boas data structure, the operation can be performed on an associative
array. Hence, the time complexity for searching a key or integer in Van Emde Boas data structure is O (log (log M)).
27. The optimal data structure used to solve Tower of Hanoi is _________
a) Tree
b) Heap
c) Priority queue
d) Stack
View Answer
Answer: d
Explanation: The Tower of Hanoi involves moving of disks ‘stacked’ at one peg to another peg with respect to the size constraint. It is
conveniently done using stacks and priority queues. Stack approach is widely used to solve Tower of Hanoi.
31. Which of the following is the simplest data structure that supports range searching?
a) AA-trees
b) K-d trees
c) Heaps
d) binary search trees
View Answer
Answer: b
Explanation: K-d trees are the simplest data structure that supports range searching and also it achieves the respectable running time.
35. A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?
a) Priority queue
b) Dequeue
c) Circular queue
d) Queue
View Answer
Answer: b
Explanation: In dequeuer, we can insert or delete elements from both the ends. In queue, we will follow first in first out principle for insertion
and deletion of elements. Element with least priority will be deleted in a priority queue.
1. The word ____________comes from the name of a Persian mathematician Abu Ja’far Mohammed ibn-i Musa al Khowarizmi.
a) Flowchart
b) Flow
c) Algorithm
d) Syntax
View Answer
Answer: c
Explanation: The word algorithm comes from the name of a Persian mathematician Abu Ja’far Mohammed ibn-i Musa al Khowarizmi.
2. In computer science, algorithm refers to a special method usable by a computer for the solution to a problem.
a) True
b) False
View Answer
Answer: a
Explanation: The statement is true. This word algorithm refers to a special method usable by a computer for the solution to a problem. The
statement of the problem specifies in general terms the desired input/output relationship.
3. This characteristic often draws the line between what is feasible and what is impossible.
a) Performance
b) System Evaluation
c) Modularity
d) Reliability
View Answer
Answer: a
Explanation: Algorithms help us to understand scalability. Performance often draws the line between what is feasible and what is impossible.
advertisement
4. The time that depends on the input: an already sorted sequence that is easier to sort.
a) Process
b) Evaluation
c) Running
d) Input
View Answer
Answer: c
Explanation: The running time depends on the input: an already sorted sequence is easier to sort. The running time is given by the size of
the input, since short sequences are easier to sort than the longer ones. Generally, we seek upper bounds on the running time, because it is
reliable.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
8. A system wherein items are added from one and removed from the other end.
a) Stack
b) Queue
c) Linked List
d) Array
View Answer
Answer: b
Explanation: In a queue, the items are inserted from the rear end and deleted from the front end.