DS MCQs

Download as pdf or txt
Download as pdf or txt
You are on page 1of 73

Data Structure & Algorithm

Q-1: What is recurrence for worst case of QuickSort and what is the time complexity
in Worst case?
(A) Recurrence is T(n) = T(n-2) + O(n) and time complexity is O(n^2)
(B) Recurrence is T(n) = T(n-1) + O(n) and time complexity is O(n^2)
(C) Recurrence is T(n) = 2T(n/2) + O(n) and time complexity is O(nLogn)
(D) Recurrence is T(n) = T(n/10) + T(9n/10) + O(n) and time complexity is O(nLogn)

ANS B
Data Structure & Algorithm
Q-2:
Which of the given options provides the increasing order of asymptotic
complexity of functions f1, f2, f3 and f4?
f1(n) = 2^n
f2(n) = n^(3/2)
f3(n) = nLogn
f4(n) = n^(Logn)
(A) f3, f2, f4, f1
(B) f3, f2, f1, f4
(C) f2, f3, f1, f4
(D) f2, f3, f4, f1
Data Structure & Algorithm
Q-3: Consider the following functions:
f(n) = 2^n
g(n) = n!
h(n) = n^logn
Which of the following statements about the asymptotic behavior of f(n), g(n), and h(n) is true?
(A) f(n) = O(g(n)); g(n) = O(h(n))
(B) f(n) = (g(n)); g(n) = O(h(n))
(C) g(n) = O(f(n)); h(n) = O(f(n))
(D) h(n) = O(f(n)); g(n) = O(f(n));
Data Structure & Algorithm
Q-4:Consider the following three claims
I (n + k)^m = (n^m), where k and m are constants
II 2^(n + 1) = 0(2^n)
III 2^(2n + 1) = 0(2^n)
Which of these claims are correct? (GATE CS 2003)
(A) I and II
(B) I and III
(C) II and III
(D) I, II and III
Data Structure & Algorithm

Q-5: The minimum number of comparisons required to find the minimum


and the maximum of 100 numbers is ______________.
(A) 148
(B) 147
(C) 146
(D) 140
ANS A
Data Structure & Algorithm
Q-6: The time complexity of the following C function is (assume n > 0)
int recursive (int n)
{
if(n == 1)return (1);
else
return (recursive (n-1) + recursive (n-1));
}
(A) O(n)
(B) O(n log n)
(C) O(n2)
(D) O(2n) ANS
Data Structure & Algorithm
Q-7: The solution to the recurrence equation T(2 k) = 3 T(2k-1) + 1, T (1) = 1, is:
(A) 2k
(B) (3k + 1 – 1)/2
(C) 3l og2k
(D) 2l og3k
Data Structure & Algorithm
Q-8: Consider a two dimensional array A[20][10]. Assume 4 words per memory cell, the base
address of array A is 100, elements are stored in row-major order and first element is A[0][0].
What is the address of A[11][5] ?
(A) 560
(B) 460
(C) 570
(D) 575
Data Structure & Algorithm
Q-9:What does the following function do for a given Linked List with first node as head?
void fun1(struct node* head)
{
if(head == NULL)
return;

fun1(head->next);
printf("%d ", head->data);
}
(A) Prints all nodes of linked lists
(B) Prints all nodes of linked list in reverse order
(C) Prints alternate nodes of Linked List
(D) Prints alternate nodes in reverse order
Data Structure & Algorithm

Q-10: 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 ANS
Data Structure & Algorithm

Q-11: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) ANS
(B) O(1) and O(1)
(C) O(n) and O(1)
(D) O(n) and O(n)
Data Structure & Algorithm
Q-12: Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What
is the worst-case time complexity of the best known algorithm to delete the node x from the list?
(A) O(n)
(B) O(log2 n)
(C) O(logn)
(D) O(1)
Data Structure & Algorithm
Q-13: The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of
length 10 using open addressing with hash function h(k) = k mod 10 and linear probing. What is
the resultant hash table?
Data Structure & Algorithm
Q-14: Which of the following is not a stable sorting
algorithm in its typical implementation.
(A) Insertion Sort
(B) Merge Sort
(C) Quick Sort ANS
(D) Bubble Sort
Data Structure & Algorithm
Q-15: The concatenation of two lists is to be performed in O(1) time. Which of the following
implementations of a list should be used?
(A) singly linked list
(B) doubly linked list
(C) circular doubly linked list ANS
(D) array implementation of lists
Data Structure & Algorithm
Q-16: Which of the following sorting algorithms in its typical implementation
gives best performance when applied on an array which is sorted or almost
sorted (maximum 1 or two elements are misplaced).
(A) Quick Sort
(B) Heap Sort
(C) Merge Sort
(D) Insertion Sort ANS
Data Structure & Algorithm

Q-17: Consider a situation where swap operation is very costly. Which of the
following sorting algorithms should be preferred so that the number of swap
operations are minimized in general?
(A) Heap Sort
(B) Selection Sort ANS
(C) Insertion Sort
(D) Merge Sort
Data Structure & Algorithm
Q-18: Suppose there are two singly linked lists both of which intersect at some point and become a single
linked list. The head or start pointers of both the lists are known, but the intersecting node and lengths of
lists are not known.
What is worst case time complexity of optimal algorithm to find intersecting node from two intersecting
linked lists?
(A) Θ(n*m), where m, n are lengths of given lists
(B) Θ(n^2), where m>n and m, n are lengths of given lists
(C) Θ(m+n), where m, n are lengths of given lists ANS
(D) Θ(min(n, m)), where m, n are lengths of given lists
Data Structure & Algorithm

Q-19: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 ANS
(B) 5, 7
(C) 3, 2
(D) 1, 5
Data Structure & Algorithm
Q-20: Let S be a stack of size n >= 1. Starting with the empty stack, suppose we push the first n
natural numbers in sequence, and then perform n pop operations. Assume that Push and Pop
operation take X seconds each, and Y seconds elapse between the end of one such stack
operation and the start of the next operation. For m >= 1, define the stack-life of m as the time
elapsed from the end of Push(m) to the start of the pop operation that removes m from S. The
average stack-life of an element of this stack is
(A) n(X+ Y)
(B) 3Y + 2X
(C) n(X + Y)-X ANS
(D) Y + 2X
Data Structure & Algorithm
Q-21: A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite
ends of the array. Variables top1 and top2 (topl< top 2) point to the location of the topmost element in
each of the stacks. If the space is to be used efficiently, the condition for “stack full” is (GATE CS 2004)
(A) (top1 = MAXSIZE/2) and (top2 = MAXSIZE/2+1)
(B) top1 + top2 = MAXSIZE
(C) (top1= MAXSIZE/2) or (top2 = MAXSIZE)
(D) top1= top2 -1 ANS
Data Structure & Algorithm
Q-22: Suppose we are sorting an array of eight integers using quicksort, and we have
just finished the first partitioning with the array looking like this:
2 5 1 7 9 12 11 10
Which statement is correct?
(A) The pivot could be either the 7 or the 9.
(B) The pivot could be the 7, but it is not the 9
(C) The pivot is not the 7, but it could be the 9
(D) Neither the 7 nor the 9 is the pivot.
Data Structure & Algorithm

Q-23: 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
Data Structure & Algorithm
Q-24: The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is
(A) 284
(B) 213
(C) 142
(D) 71

Q-25: A function f defined on stacks of integers satisfies the following properties.


f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S
contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?
(A) 6
(B) 4
(C) 3 ANS
(D) 2
Data Structure & Algorithm
Q-26: Suppose a stack is to be implemented with a linked list instead of an array. What would
be the effect on the time complexity of the push and pop operations of the stack implemented
using linked list (Assuming stack is implemented efficiently)?
(A) O(1) for insertion and O(n) for deletion
(B) O(1) for insertion and O(1) for deletion ANS
(C) O(n) for insertion and O(1) for deletion
(D) O(n) for insertion and O(n) for deletion

Q-27: Which of the following permutation can be obtained in the same order using a stack
assuming that input is the sequence 5, 6, 7, 8, 9 in that order?
(A) 7, 8, 9, 5, 6
(B) 5, 9, 6, 7, 8
(C) 7, 8, 9, 6, 5
(D) 9, 8, 7, 5, 6
Data Structure & Algorithm
Q-28: A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear
probing. After inserting 6 values into an empty hash table, the table is as shown below.

(i) Which one of the following choices gives a possible order


in which the key values could have been inserted in the
table?
(A) 46, 42, 34, 52, 23, 33
(B) 34, 42, 23, 52, 33, 46
(C) 46, 34, 42, 23, 52, 33
(D) 42, 46, 33, 23, 34, 52

(ii) How many different insertion sequences of the key values using the hash function h(k) = k mod
10 and linear probing will result in the hash table shown below?

(A) 10
(B) 20
(C) 30
(D) 40
Data Structure & Algorithm
Q-29: You have to sort 1 GB of data with only 100 MB of available main memory.
Which sorting technique will be most appropriate?
(A) Heap sort
(B) Merge sort ANS
(C) Quick sort
(D) Insertion sort
Data Structure & Algorithm
Q-30: Suppose a circular queue of capacity (n – 1) elements is implemented with an
array of n elements. Assume that the insertion and deletion operation are carried out
using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT =
0. The conditions to detect queue full and queue empty are
(A) Full: (REAR+1) mod n == FRONT, empty: REAR == FRONT ANS
(B) Full: (REAR+1) mod n == FRONT, empty: (FRONT+1) mod n == REAR
(C) Full: REAR == FRONT, empty: (REAR+1) mod n == FRONT
(D) Full: (FRONT+1) mod n == REAR, empty: REAR == FRONT

Q-31: A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements.


The level-order traversal of the heap is given below:
10, 8, 5, 3, 2
Two new elements ”1‘ and ”7‘ are inserted in the heap in that order. The level-order
traversal of the heap after the insertion of the elements is:
(A) 10, 8, 7, 5, 3, 2, 1
(B) 10, 8, 7, 2, 3, 1, 5
(C) 10, 8, 7, 1, 2, 3, 5
(D) 10, 8, 7, 3, 2, 1, 5
Data Structure & Algorithm

Q-32: Consider a standard Circular Queue ‘q’ implementation (which has the same condition for Queue
Full and Queue Empty) whose size is 11 and the elements of the queue are q[0], q[1], q[2]…..,q[10].
The front and rear pointers are initialized to point at q[2] . In which position will the ninth element be
added?
(A) q[0]
(B) q[1]
(C) q[9]
(D) q[10]
Data Structure & Algorithm

Q-33: What is the worst case time complexity of insertion sort where position of the
data to be inserted is calculated using binary search?
(A) N
(B) NlogN
(C) N^2 ANS
(D) N(logN)^2
Data Structure & Algorithm

Q-34: Level of a node is distance from root to that node. For example, level of root is 1 and levels
of left and right children of root is 2. The maximum number of nodes on level i of a binary tree is
In the following answers, the operator ‘^’ indicates power.
(A) 2^(i-1)
(B) 2^i
(C) 2^(i+1)
(D) 2^[(i+1)/2]

Q-35: In a complete k-ary tree, every internal node has exactly k children or no child. The number
of leaves in such a tree with n internal nodes is:
(A) nk
(B) (n – 1) k+ 1
(C) n( k – 1) + 1 ANS
(D) n(k – 1)
Data Structure & Algorithm
Q-36: The tightest lower bound on the number of comparisons, in the worst case, for
comparison-based sorting is of the order of
(A) N
(B) N^2
(C) NlogN ANS
(D) N(logN)^2

Q-37: You have to sort a list L, consisting of a sorted list followed by a few ‘random’
elements. Which of the following sorting method would be most suitable for such a task?
(A) Bubble sort
(B) Selection sort
(C) Quick sort
(D) Insertion sort
Data Structure & Algorithm

Q-38: The maximum number of binary trees that can be formed with three unlabeled nodes is:
(A) 1
(B) 5 ANS
(C) 4
(D) 3

Q-39: A complete n-ary tree is a tree in which each node has n children or no children.
Let I be the number of internal nodes and L be the number of leaves in a complete
n-ary tree. If L = 41, and I = 10, what is the value of n?
(A) 6
(B) 3
(C) 4
(D) 5
Data Structure & Algorithm
Q-40: Which sorting algorithm will take least time when all elements of
input array are identical? Consider typical implementations of sorting
algorithms.
(A) Insertion Sort
(B) Heap Sort
(C) Merge Sort
(D) Selection Sort

Q-41: The average case and worst case complexities for Merge sort algorithm
are
(A) O ( n2 ), O ( n2 )
(B) O ( n2 ), O ( n log2n )
(C) O ( n log2n ), O ( n2)
(D) O ( n log2n ), O ( n log2n ) ANS
Data Structure & Algorithm

Q-42: A list of n string, each of length n, is sorted into lexicographic order using
the merge-sort algorithm. The worst case running time of this computation is
(A) O (n log n)
(B) O (n2 log n) ANS
(C) O (n2 + log n)
(D) O (n2)

Q-43: Selection sort algorithm design technique is an example of


(A) Greedy method
(B) Divide-and-conquer
(C) Dynamic Programming
(D) Backtracking
Data Structure & Algorithm
Q-44: Postorder traversal of a given binary search tree, T produces the following sequence of keys
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29
Which one of the following sequences of keys can be the result of an in-order traversal of the tree T?
(A) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95 ANS
(B) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
(C) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
(D) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

Q-45: Consider the following nested representation of binary trees: (X Y Z) indicates Y and Z are the
left and right sub stress, respectively, of node X. Note that Y and Z may be NULL, or further nested.
Which of the following represents a valid binary tree?
(A) (1 2 (4 5 6 7))
(B) (1 (2 3 4) 5 6) 7)
(C) (1 (2 3 4)(5 6 7)) ANS
(D) (1 (2 3 NULL) (4 5))
Data Structure & Algorithm
Q-46: Consider the Quicksort algorithm. Suppose there is a procedure for finding a
pivot element which splits the list into two sub-lists each of which contains at least
one-fifth of the elements. Let T(n) be the number of comparisons required to sort n
elements. Then
(A) T(n) <= 2T(n/5) + n
(B) T(n) <= T(n/5) + T(4n/5) + n ANS
(C) T(n) <= 2T(4n/5) + n
(D) T(n) <= 2T(n/2) + n
Data Structure & Algorithm

Q-47: Which of the following sorting algorithms has the lowest worst-case complexity?
(A) Merge Sort ANS
(B) Bubble Sort
(C) Quick Sort
(D) Selection Sort
Q-48: Which of the following algorithm design technique is used in merge sort?
(A) Greedy method
(B) Backtracking
(C) Dynamic programming
(D) Divide and Conquer ANS
Data Structure & Algorithm
Q-49: Which sorting algorithms is most efficient to sort string consisting of ASCII
characters?
(A) Quick sort
(B) Heap sort
(C) Merge sort
(D) Counting sort ANS

Q-50: Which one of the following in place sorting algorithms needs the minimum number of
swaps?
(A) Quick sort
(B) Insertion sort
(C) Selection sort ANS
(D) Heap sort
Data Structure & Algorithm
Q-51: Which of the following is true about merge sort?
(A) Merge Sort works better than quick sort if data is accessed from slow
sequential memory.
(B) Merge Sort is stable sort by nature
(C) Merge sort outperforms heap sort in most of the practical situations.
(D) All of the above.

Q-52: Which of the following algorithms sort n integers, having the range 0 to (n 2 – 1),
in ascending order in O(n) time ?
(A) Selection sort
(B) Bubble sort
(C) Radix sort ANS
(D) Insertion sort
Data Structure & Algorithm
Q-53: Given an array where numbers are in range from 1 to n6, which sorting algorithm
can be used to sort these number in linear time?
(A) Not possible to sort in linear time
(B) Radix Sort ANS
(C) Counting Sort
(D) Quick Sort

Q-54: Consider the following sorting algorithms.


I. Quicksort
II. Heapsort
III. Mergesort
Which of them perform in least time in the worst case?
(A) I and II only
(B) II and III only ANS
(C) III only
(D) I, II and III
Data Structure & Algorithm

Q-55: The height of a tree is the length of the longest root-to-leaf path in it. The maximum and
minimum number of nodes in a binary tree of height 5 are
(A) 63 and 6, respectively ANS
(B) 64 and 5, respectively
(C) 32 and 6, respectively
(D) 31 and 5, respectively

Q-56: A binary tree T has 20 leaves. The number of nodes in T having two children is
(A) 18
(B) 19 ANS
(C) 17
(D) Any number between 10 and 20
Data Structure & Algorithm
Q-57: In a binary tree, the number of internal nodes of degree 1 is 5, and the number
of internal nodes of degree 2 is 10. The number of leaf nodes in the binary tree is

(A) 10
(B) 11 ANS
(C) 12
(D) 15

Q-58: The following three are known to be the preorder, inorder and postorder
sequences of a binary tree. But it is not known which is which.
MBCAFHPYK
KAMCBYPFH
MABCKYFPH
Pick the true statement from the following.
(A) I and II are preorder and inorder sequences, respectively
(B) I and III are preorder and postorder sequences, respectively
(C) II is the inorder sequence, but nothing more can be said about the other two
sequences
(D) II and III are the preorder and inorder sequences, respectively
Data Structure & Algorithm

Q-59: Let P be a QuickSort Program to sort numbers in ascending order using the first
element as pivot. Let t1 and t2 be the number of comparisons made by P for the inputs
{1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds?
(A) t1 = 5
(B) t1 < t2
(C) t1 > t2 ANS
(D) t1 = t2

Q-60: Which of the following is true for computation time in insertion, deletion and finding
maximum and minimum element in a sorted array ?
(A) Insertion – 0(1), Deletion – 0(1), Maximum – 0(1), Minimum – 0(l)
(B) Insertion – 0(1), Deletion – 0(1), Maximum – 0(n), Minimum – 0(n)
(C) Insertion – 0(n), Deletion – 0(n), Maximum – 0(1), Minimum – 0(1)
(D) Insertion – 0(n), Deletion – 0(n), Maximum – 0(n), Minimum – 0(n
Data Structure & Algorithm
Q-61: You have an array of n elements. Suppose you implement quicksort by always
choosing the central element of the array as the pivot. Then the tightest upper bound for the
worst case performance is
(A) O(n2) ANS
(B) O(nLogn)
(C) Theta(nLogn)
(D) O(n3)

Q-62: A sorting technique is called stable if


(A) If it takes O(n log n) time
(B) It uses divide and conquer technique
(C) Relative order of occurrence of non-distinct elements is maintained ANS
(D) It takes O(n) space
Data Structure & Algorithm
Q-63: In a permutation a1…..an of n distinct integers, an inversion is a pair (ai, aj) such that i aj. What
would be the worst case time complexity of the Insertion Sort algorithm, if the inputs are restricted to
permutations of 1…..n with at most n inversions?
(A) Θ (n2) ANS
(B) Θ (n log n)
(C) Θ (n1.5)
(D) Θ (n)

Q-64: Quicksort is run on two inputs shown below to sort in ascending order taking first element as pivot,
(i) 1, 2, 3,......., n
(ii) n, n-1, n-2,......, 2, 1
Let C1 and C2 be the number of comparisons made for the inputs (i) and (ii) respectively. Then,
(A) C1 < C2
(B) C1 > C2
(C) C1 = C2 ANS
(D) We cannot say anything for arbitrary n
Data Structure & Algorithm
Q-65: Randomized quicksort is an extension of quicksort where the pivot is chosen
randomly. What is the worst case complexity of sorting n numbers using
randomized quicksort?
(A) O(n)
(B) O(n Log n)
(C) O(n2) ANS
(D) O(n!)

Q-66: If one uses straight two-way merge sort algorithm to sort the following elements in
ascending order 20, 47, 15, 8, 9, 4, 40, 30, 12, 17
then the order of these elements after the second pass of the algorithm is:
(A) 8, 9, 15, 20, 47, 4, 12, 17, 30, 40
(B) 8, 15, 20, 47, 4, 9, 30, 40, 12, 17
(C) 15, 20, 47, 4, 8, 9, 12, 30, 40, 17
(D) 4, 8, 9, 15, 20, 47, 12, 17, 30, 40
Data Structure & Algorithm
Q-67: Which one of the following is the recurrence equation for the worst case time complexity of the
Quicksort algorithm for sorting n(≥ 2) numbers? In the recurrence equations given in the options below,
c is a constant.
(A) T(n) = 2T (n/2) + cn
(B) T(n) = T(n – 1) + T(0) + cn ANS
(C) T(n) = 2T (n – 2) + cn
(D) T(n) = T(n/2) + cn

Q-69: A sorting technique is called stable if:


(A) It takes O(nlog n)time
(B) It maintains the relative order of occurrence of non-distinct elements ANS
(C) It uses divide and conquer paradigm
(D) It takes O(n) space
Data Structure & Algorithm

Q-70: A strictly binary tree with 10 leaves


(A) cannot have more than 19 nodes
(B) has exactly 19 nodes ANS
(C) has exactly 17 nodes
(D) has exactly 20 nodes

Q-71: What is the maximum height of any AVL tree with 7 nodes? Assume that height
of tree with single node is 0.
(A) 2
(B) 3 ANS
(C) 4
(D) 5
Data Structure & Algorithm

Q-72: The following numbers are inserted into an empty binary search tree in the given order:
10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum
distance of a leaf node from the root)? (GATE CS 2004)
(A) 2
(B) 3
(C) 4
(D) 6
Data Structure & Algorithm
Q-73: Assume that a mergesort algorithm in the worst case takes 30 seconds for an
input of size 64. Which of the following most closely approximates the maximum input
size of a problem that can be solved in 6 minutes?
(A) 256
(B) 512 ANS
(C) 1024
(D) 2048

Q-74:Which of the below given sorting techniques has highest best-case runtime complexity.
(A) Quick sort
(B) Selection sort
(C) Insertion sort
(D) Bubble sort
Data Structure & Algorithm

Q-75: The worst case running times of Insertion sort, Merge sort and Quick sort, respectively,
are:
(A) Θ(n log n), Θ(n log n) and Θ(n2)
(B) Θ(n2), Θ(n2) and Θ(n Log n)
(C) Θ(n2), Θ(n log n) and Θ(n log n)
(D) Θ(n2), Θ(n log n) and Θ(n2) ANS

Q-76: What is the best sorting algorithm to use for the elements in array are more than 1
million in general?
(A) Merge sort. ANS
(B) Bubble sort.
(C) Quick sort.
(D) Insertion sort.
Data Structure & Algorithm
Q-77: Assume that the algorithms considered here sort the input sequences in ascending order. If
the input is already in ascending order, which of the following are TRUE ?
I. Quicksort runs in Θ(n2) time
II. Bubblesort runs in Θ(n2) time
III. Mergesort runs in Θ(n) time
IV. Insertion sort runs in Θ(n) time
(A) I and II only
(B) I and III only
(C) II and IV only
(D) I and IV only ANS
Data Structure & Algorithm
Q-78: Assume that we use Bubble Sort to sort n distinct elements in ascending
order. When does the best case of Bubble Sort occur?
(A) When elements are sorted in ascending order ANS
(B) When elements are sorted in descending order
(C) When elements are not sorted by any order
(D) There is no best case for Bubble Sort. It always takes O(n*n) time

Q-79: The auxiliary space of insertion sort is O(1), what does O(1) mean ?
(A) The memory (space) required to process the data is not constant.
(B) It means the amount of extra memory Insertion Sort consumes doesn’t depend on
the input. The algorithm should use the same amount of memory for all inputs. ANS
(C) It takes only 1 kb of memory .
(D) It is the speed at which the elements are traversed.
Data Structure & Algorithm
Q-80: If we use Radix Sort to sort n integers in the range (nk/2,nk], for some k>0
which is independent of n, the time taken would be?
(A) Θ(n)
(B) Θ(kn)
(C) Θ(nlogn) ANS
(D) Θ(n2)

Q-81: Which is the correct order of the following algorithms with respect to their time
Complexity in the best case ?
(A) Merge sort > Quick sort >Insertion sort > selection sort
(B) insertion sort < Quick sort < Merge sort < selection sort ANS
(C) Merge sort > selection sort > quick sort > insertion sort
(D) Merge sort > Quick sort > selection sort > insertion sort
Data Structure & Algorithm

Q-83: The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42.
Which one of the following is the postorder traversal sequence of the same tree?
(A) 10, 20, 15, 23, 25, 35, 42, 39, 30
(B) 15, 10, 25, 23, 20, 42, 35, 39, 30
(C) 15, 20, 10, 23, 25, 42, 35, 39, 30
(D) 15, 10, 23, 25, 20, 35, 42, 39, 30
Data Structure & Algorithm

Q-84: You are given the postorder traversal, P, of a binary search tree on the n elements 1, 2, …, n. You
have to determine the unique binary search tree that has P as its postorder traversal. What is the time
complexity of the most efficient algorithm for doing this?
(A) O(Logn)
(B) O(n)
(C) O(nLogn)
(D) none of the above, as the tree cannot be uniquely determined.
Data Structure & Algorithm

Q-85: Suppose we have a balanced binary search tree T holding n numbers. We are given
two numbers L and H and wish to sum up all the numbers in T that lie between L and H.
Suppose there are m such numbers in T. If the tightest upper bound on the time to
compute the sum is O(na logb n + mc logd n), the value of a + 10b + 100c + 1000d is ____.
(A) 60
(B) 110 ANS
(C) 210
(D) 50
Data Structure & Algorithm
Q-86: Let T(n) be the number of different binary search
trees on n distinct elements.

Then

where x is
(A) n-k+1
(B) n-k ANS
(C) n-k-1
(D) n-k-2
Data Structure & Algorithm
Q-87: Suppose that we have numbers between 1 and 100 in a binary search tree
and want to search for the number 55. Which of the following sequences CANNOT
be the sequence of nodes examined?
(A) {10, 75, 64, 43, 60, 57, 55}
(B) {90, 12, 68, 34, 62, 45, 55}
(C) {9, 85, 47, 68, 43, 57, 55} ANS
(D) {79, 14, 72, 56, 16, 53, 55}
Data Structure & Algorithm

Q-88: Postorder traversal of a given binary search tree T produces following sequence of keys:
3, 5, 7, 9, 4, 17, 16, 20, 18, 15, 14
Which one of the following sequences of keys can be the result of an in-order traversal of the
tree T?
(A) 3, 4, 5, 7, 9, 14, 20, 18, 17, 16, 15
(B) 20, 18, 17, 16, 15, 14, 3, 4, 5, 7, 9
(C) 20, 18, 17, 16, 15, 14, 9, 7, 5, 4, 3
(D) 3, 4, 5, 7, 9, 14, 15, 16, 17, 18, 20
Data Structure & Algorithm

Q-89: What is the maximum height of any AVL-tree with 7 nodes? Assume that the
height of a tree with a single node is 0.
(A) 2
(B) 3
(C) 4
(D) 5
Data Structure & Algorithm
Q-90: A B-tree of order 4 is built from scratch by 10 successive insertions. What is the maximum
number of node splitting operations that may take place?
(A) 3
(B) 4
(C) 5 ANS
(D) 6
Data Structure & Algorithm

Q-91: Which of the following standard algorithms is not


Dynamic Programming based.
(A) Bellman–Ford Algorithm for single source shortest path
(B) Floyd Warshall Algorithm for all pairs shortest paths
(C) 0-1 Knapsack problem
(D) Prim’s Minimum Spanning Tree ANS
Data Structure & Algorithm

Q-96: Which of the following standard algorithms is not a


Greedy algorithm?
(A) Dijkstra’s shortest path algorithm
(B) Prim’s algorithm
(C) Kruskal algorithm
(D) Huffman Coding
(E) Bellmen Ford Shortest path algorithm ANS
Data Structure & Algorithm
Q-99: For the undirected, weighted graph given below,
which of the following sequences of edges represents
a correct execution of Prim’s algorithm to construct a
Minimum Spanning Tree?

(A) (a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)
(B) (c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)
(C) (d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)
(D) (h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)
Data Structure & Algorithm

Q-100: Which of the following data structure is useful in traversing a


given graph by breadth first search?
(A) Stack
(B) List
(C) Queue
(D) None of the above
Data Structure & Algorithm
Q-101: Suppose we run Dijkstra’s single source shortest-path algorithm on the following edge
weighted
directed graph with vertex P as the source. In what order do the nodes get included into the set of
vertices for which the shortest path distances are finalized?

(A) P, Q, R, S, T, U
(B) P, Q, R, U, S, T
(C) P, Q, R, U, T, S
(D) P, Q, T, R, U, S
Data Structure & Algorithm

Q-102: Let G(V, E) an undirected graph with positive edge weights. Dijkstra’s single-source
shortest path algorithm can be implemented using the binary heap data structure with time
complexity:
(A) O(| V |2)
(B) O (| E | + | V | log | V |)
(C) O (| V | log | V |)
(D) O ((| E | + | V |) log | V
Data Structure & Algorithm

Q-103: Consider the following graph:

Which one of the following is NOT the sequence of edges


added to
the minimum spanning tree using Kruskal’s algorithm?
(A) (b,e)(e,f)(a,c)(b,c)(f,g)(c,d)
(B) (b,e)(e,f)(a,c)(f,g)(b,c)(c,d)
(C) (b,e)(a,c)(e,f)(b,c)(f,g)(c,d)
(D) (b,e)(e,f)(b,c)(a,c)(f,g)(c,d)
Data Structure & Algorithm
Q-104: What is the weight of a minimum spanning tree of the following graph ?

(A) 29
(B) 31
(C) 38
(D) 41
Data Structure & Algorithm

Q-106: The characters a to h have the set of frequencies based on the first 8 Fibonacci numbers as follows
a: 1, b: 1, c: 2, d: 3, e: 5, f: 8, g:13, h: 21.
A Huffman code is used to represent the characters. What is the sequence of characters corresponding
to the following code? 110111100111010
(A) fdheg
(B) ecgdf
(C) dchfg
(D) fehdg
Data Structure & Algorithm

Q-108: Suppose the letters a, b, c, d, e, f have probabilities 1/2, 1/4, 1/8, 1/16, 1/32, 1/32
respectively.
(i) Which of the following is the Huffman code for the letter a, b, c, d, e, f?
(A) 0, 10, 110, 1110, 11110, 11111
(B) 11, 10, 011, 010, 001, 000
(C) 11, 10, 01, 001, 0001, 0000
(D) 110, 100, 010, 000, 001, 111
(ii) What is the average length of Huffman codes?
(A) 3
(B) 2.1875
(C) 2.25
(D) 1.9375

You might also like