Data structure(mcq)
1. What is a data structure?
a) A programming language
b) A collection of algorithms
c) A way to store and organize data
d) A type of computer hardware
2. Which of the following is not the application of stack?
a) Data Transfer between two asynchronous process
b) Compiler Syntax Analyzer
c) Tracking of local variables at run time
d) A parentheses balancing program
3. Which of the following tree data structures is not a balanced binary tree?
a) Splay tree
b) B-tree
c) AVL tree
d) Red-black tree
4. What is the number of edges present in a complete graph having n vertices?
a) (n*(n+1))/2
b) (n*(n-1))/2
c) n
d) Information given is insufficient
5. A graph with all vertices having equal degree is known as a __________
a) Multi Graph
b) Regular Graph
c) Simple Graph
d) Complete Graph
6. Which of the following ways can be used to represent a graph?
a) Adjacency List and Adjacency Matrix
b) Incidence Matrix
c) Adjacency List, Adjacency Matrix as well as Incidence Matrix
d) No way to represent
7. Which of the following traversing algorithm is not used to traverse in a tree?
a) Post order
b) Pre order
c) Post order
d) Randomized
8. Level order traversal of a tree is formed with the help of
a) breadth first search
b) depth first search
c) dijkstra’s algorithm
d) prims algorithm
9. If binary trees are represented in arrays, what formula can be used to locate a
left child, if the node has an index i?
a) 2i+1
b) 2i+2
c) 2i
d) 4i
10. Which of the following properties are obeyed by all three tree – traversals?
a) Left subtrees are visited before right subtrees
b) Right subtrees are visited before left subtrees
c) Root node is visited before left subtree
d) Root node is visited before right subtree
11.
The below formula is used by which tree?
left_subtree (keys) ≤ node (key) ≤ right_subtree (keys)
A. Red Black Tree
B. AVL Tree
C. Binary Search Tree
D. B+ Tree
12. What is the minimum number of spanning tree(s) in a
connected graph?
A. 1
B. n
C. nxn
D. 0
13. Queue can be used for?
A. Parsing expression
B. Recursion
C. Resource Allocation
D. None of the above
14. Which of the following conditions is required to be met for
interpolation search to work?
A. Collection should be in sorted form and equally distributed
B. Collection should not be in sorted form but should be equally
distributed
C. Collection should not be equally distributed but should be
sorted form
D. None of the above
15. Which of the following asymptotic notations is the worst
among all?
A. O(n)
B. O(1)
C. O(n^3)
D. O(2n)
16. How many edges are required to make a cyclic graph of n
vertices?
A. n-1
B. 2n
C. n
D. n+1
17. How many moves are required as minimum to solve the
Tower of Hanoi problem?
A. n
B. 2n
C. 2n-1
D. 2^n-1
18. Which of the following correctly defines the Tower of Hanoi
problem?
A. Divide and Conquer
B. Recursive
C. Both of the above
D. None of the above
19. The recurrence relation capturing the optimal time of the Tower of Hanoi
problem with n discs is
a.
T(n) = 2T(n – 2) + 2
b.
T(n) = 2T(n – 1) + n
c.
T(n) = 2T(n/2) + 1
d.
T(n) = 2T(n – 1) + 1
20. Which of the following sorting algorithms can be used to sort a random linked list
with minimum time complexity?
a.
Insertion Sort
b.
Quick Sort
c.
Heap Sort
d.
Merge Sort
21.
What is the output of following function for start pointing to first node of following
linked list?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}
a.
146641
b.
135135
c.
1235
d.
135531
22. In the worst case, the number of comparisons needed to search a singly linked
list of length n for a given element is
a.
log 2 n
b.
n/2
c.
log 2 n – 1
d.
23.
What are the time complexities of finding 8th element from beginning and 8th
element from end in a singly linked list? Let n be the number of nodes in linked list,
you may assume that n > 8.
a.
O(1) and O(n)
b.
O(1) and O(1)
c.
O(n) and O(1)
d.
O(n) and O(n)
24. Which one of the following is an application of Stack Data Structure?
a.
Managing function calls
b.
The stock span problem
c.
Arithmetic expression evaluation
d.
All of the above
25. hich of the following is true about linked list implementation of stack?
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
26. The following postfix expression with single digit operands is evaluated using a
stack:
823^/23*+51*-
Note that ^ is the exponentiation operator. The top two elements of the stack after
the first * is evaluated are:
a.
6, 1
b.
5, 7
c.
3, 2
d.
1, 5
27. 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
28. The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is
a.
284
b.
213
c.
142
d.
71
29.
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.
b.
2
c.
d.
30. 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
31. The most appropriate matching for the following pairs
X: depth first search 1: heap
Y: breadth-first search 2: queue
Z: sorting 3: stack
is
a.
X—1, Y—2 ,Z --3
b.
X—3, Y—1, Z --2
c.
X—3, Y—2, Z--1
d.
X—2 ,Y—3 ,Z--1
32. The number of tokens in the following C statement
printf("i = %d, &i = %x", i, &i);
is
a.
b.
26
c.
10
d.
21
33. How many perfect matchings are there in a complete graph of 6 vertices ?
a.
15
b.
24
c.
30
d.
60
34. Consider the following C function:
int f(int n)
{
static int i = 1;
if (n >= 5)
return n;
n = n+i;
i++;
return f(n);
}
The value returned by f(1) is
a.
b.
c.
d.
35. What is the name for the adjacency matrix?
a.
Boolean Matrix
b.
Digraph Matrix
c.
Tree Matrix
d.
Traversal Matrix
36. What is a threaded binary tree traversal?
a) a binary tree traversal using stacks
b) a binary tree traversal using queues
c) a binary tree traversal using stacks and queues
d) a binary tree traversal without using stacks and queues
36. What are double and single threaded trees?
a) when both left, right nodes are having null pointers and only right node is null pointer
respectively
b) having 2 and 1 node
c) using single and double linked lists
d) using heaps and priority queues
37. How many passes does an insertion sort algorithm consist of?
a) N
b) N-1
c) N+1
d) N2
38.What is the running time of an insertion sort algorithm if the input is pre-sorted?
a) O(N2)
b) O(N log N)
c) O(N)
d) O(M log N)
39. Which of the following is not an exchange sort?
a) Bubble Sort
b) Quick Sort
c) Partition-exchange Sort
d) Insertion Sort
40. In the following scenarios, when will you use selection sort?
a) The input is already sorted
b) A large file has to be sorted
c) Large values need to be sorted with small keys
d) Small values need to be sorted with large keys
41. What is an external sorting algorithm?
a) Algorithm that uses tape or disk during the sort
b) Algorithm that uses main memory during the sort
c) Algorithm that involves swapping
d) Algorithm that are considered ‘in place’
42. What is an internal sorting algorithm?
a) Algorithm that uses tape or disk during the sort
b) Algorithm that uses main memory during the sort
c) Algorithm that involves swapping
d) Algorithm that are considered ‘in place’
43. What is the average case complexity of bubble sort?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
44. Which of the following is not a stable sorting algorithm?
a) Quick sort
b) Cocktail sort
c) Bubble sort
d) Merge sort
45. What is the average case time complexity of standard merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
46. Which of the following sorting algorithms is the fastest?
a) Merge sort
b) Quick sort
c) Insertion sort
d) Shell sort
47. Quick sort uses which of the following algorithm to implement sorting?
a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming
48. Which of the following is not an application of binary search?
a) To find the lower/upper bound in an ordered sequence
b) Union of intervals
c) Debugging
d) To search in unordered list
49. In which of the cases uniform binary search fails compared to binary search?
a) A table lookup is generally faster than an addition and a shift
b) Many searches will be performed on the same array
c) Many searches will be performed on several arrays of the same length
d) Complexity of code
50. The time complexity of the solution tower of hanoi problem using recursion is
_________
a) O(n2)
b) O(2n)
c) O(n log n)
d) O(n)