Algorithm Gate Previous Year Questions
Ques 1DAA
Consider the following recurrence:
f(2n) = 2f(n) -1, for n≥1;
f(2n+1) = 2f(n) +1, for n≥1;
Then, which of the following statements is/are TRUE?
a) f(2n–1)=2n–1
b) f(2n)=1
c) f(5⋅2n)=2n+1+1
d) f(2n+1)=2n+1
a,b,c is the correct answer.
Ques 2DAA
Which one of the following statements is TRUE for all positive functions f (n) ?
a) f(n2)=θ(f(n)2),when f(n) is a polynomial
b) f(n2)=o(f(n)2)
c) f(n2)=O(f(n)2),when f(n) is a exponential
d) f(n2)=Ω(f(n)2)
a is the correct answer.
Ques 3DAA
Let P be an array containing n integers. Let t be the lowest upper bound on the number of comparisons of the array elements, required to find the minimum and maximum values in an arbitrary array of n elements. Which one of the following choices is correct?
a) t>2n−2
b) t>3⌈n/2⌉ and t≤2n−2
c) t>n and t≤3⌈n/2⌉
d) t>⌈log2(n)⌉ and t≤n
b is the correct answer.
Ques 4DAA
Consider the following three functions.
f1 = 10n
f2 = nlogn
f3 = n√n
Which one of the following options arranges the functions in the increasing order of asymptotic growth rate?
a) f3,f2,f1
b) f2,f1,f3
c) f1,f2,f3
d) f2,f3,f1
d is the correct answer.
Ques 5DAA
What is the worst case time complexity of inserting n elements into an empty linked list, if the linked list needs to be maintained in sorted order ?
a) Θ(n)
b) Θ(nlogn)
c) Θ(n2)
d) Θ(1)
c is the correct answer.
Ques 6DAA
What is the worst case time complexity of inserting n2 elements into an AVL-tree with n elements initially ?
a) Θ(n4)
b) Θ(n2)
c) Θ(n2log(n))
d) Θ(n3)
c is the correct answer.
Ques 7DAA
For parameters a and b, both of which are ω(1), T(n)=T(n1/a)+1, and T(b)=1. Then T(n) is
a) Θ(logalogbn)
b) Θ(logabn)
c) Θ(logblogan)
d) Θ(log2log2n)
a is the correct answer.
Ques 8DAA
The number of permutations of the characters in LILAC so that no character appears in its original position, if the two L’s are indistinguishable, is ________ .
12 is the correct answer.
Ques 9DAA
Consider a sequence of 14 elements: A = [-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0]. The subsequence sum ∑jk=iA[k]. Determine the maximum of S(i,j), where 0 ≤ i ≤ j < 14. (Divide and conquer approach may be used)
a is the correct answer.
Ques 10DAA
An array of 25 distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to 2 decimal places) is _________.
a is the correct answer.
Ques 11DAA
There are n unsorted arrays: A1, A2, ....,An. Assume that n is odd. Each of A1, A2, ...., An contains n distinct elements. There are no common elements between any two arrays. The worst-case time complexity of computing the median of the medians of A1 ,A2, ....,An is ________ .
a) Ο(n)
b) Ο(n2)
c) Ο(n log n)
d) Ω(n2log n)
b is the correct answer.
Ques 12DAA
Consider the following table
Algorithms | Design Paradigms |
---|---|
(P) Kruskal | (i) Divide and Conquer |
(Q) Quicksort | (ii) Greedy |
(R) Floyed Warshall | (iii) Dynamic Programming |
Match the algorithm to design paradigms they are based on:
a) P-(ii), Q-(iii), R-(i)
b) P-(iii), Q-(i), R-(ii)
c) P-(ii), Q-(i), R-(iii)
d) P-(i), Q-(ii), R-(iii)
Algorithms is the correct answer.
Ques 13DAA
Consider the following functions from positives integers to real numbers
10, √n, n, log2n, 100/n.
The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:
a) log2n, 100/n,10, √n, n,
b) 100/n,10,log2n, √n, n,
c) 10,100/n, √n,log2n,n
d) 100/n,log2n, 10,√n, n,
Complexity is the correct answer.
Ques 14DAA
Consider the following intermediate program in three address code
q = p * c
p = u * v
q = p+q
Which one of the following corresponds to a static single assignment from the above code?
a) p1 = a - b
q1 =p1 * c
p1= u * v
q1 =p1 + q1
b) p3= a - b
q4= p3* c
p4= u * v
q5 =p4+ q4
c) p1 = a - b
q1=p2 * c
p3= u * v
q2= p4 + q3
d) p1 = a - b
q1= p * c
p2= u * v
q2= p + q
Addressing Mode is the correct answer.
Ques 15DAA
Let A1, A2, A3, and A4 be four matrices of dimensions 10 x 5, 5 x 20, 20 x 10, and 10 x 5, respectively. The minimum number of scalar multiplications required to find the product A1 A2A3A4 using the basic matrix multiplication method is______________.
a is the correct answer.
Ques 16DAA
Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the maximum possible value of n is ________
a is the correct answer.
Ques 17DAA
N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed.
An algorithm performs the following operations on the list in this order:
Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key What is the time complexity of all these operations put together
a) O(Log2N)
b) O(N)
c) O(N2)
d) Θ(N2 Log N)
Sorting Searching is the correct answer.
Ques 18DAA
The Floyd-Warshall algorithm for all-pair shortest paths computation is based on
a) Greedy paradigm.
b) Divide-and-Conquer paradigm.
c) Dynamic Programming paradigm.
d) neither Greedy nor Divide-and-Conquer nor Dynamic Programming paradigm.
Graph Theory is the correct answer.
Ques 19DAA
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
Complexity is the correct answer.
Ques 20DAA
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), Θ(n22) and Θ(n Log n)
c) Θ(n2), Θ(n log n) and Θ(n log n)
d) Θ(n2), Θ(n log n) and Θ(n2)
Complexity is the correct answer.
Ques 21DAA
Consider two decision problems Q1, Q2 such that Q1 reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time to Q2. Then which one of the following is consistent with the above statement?
a) Q1 is in NP, Q2 is NP hard
b) Q2 is in NP, Q1 is NP hard
c) Both Q1 and Q2 are in NP
d) Both Q1 and Q2 are in NP hard
NP Hard Problem is the correct answer.
Ques 22DAA
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
c) T(n)=2T(n–2)+cn
d) T(n)=T(n/2)+cn
Complexity is the correct answer.
Ques 23DAA
Match the following
(P) Prim’s algorithm for minimum spanning tree | (i) Backtracking |
(Q) Floyd-Warshall algorithm for all pairs shortest paths | (ii) Greedy method |
(R) Mergesort | (iii) Dynamic programming |
(S) Hamiltonian circuit | (iv) Divide and conquer |
a) P-iii, Q-ii, R-iv, S-i
b) P-i, Q-ii, R-iv, S-iii
c) P-ii, Q-iii, R-iv, S-i
d) P-ii, Q-i, R-iii, S-iv
Algorithms is the correct answer.
Ques 24DAA
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
d) t1 = t2
Sorting Algorithm is the correct answer.