Design Algorithm Analysis GATE previous year questions with answer

Ques 14 Gate 2019


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 15 Gate 2019


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 16 Gate 2019


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 17 Gate 2017 Set-1


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 18 Gate 2017 Set-1


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 19 Gate 2017 Set-1


Consider the following intermediate program in three address code

p = a - b
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 20 Gate 2016 Set-2


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 21 Gate 2016 Set-2


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 22 Gate 2016 Set-2


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)


(S) is the correct answer.

Given:
A sorted doubly linked list containing N items.
Pointers are provided directly to the nodes for delete and decrease-key operations.
Sequence of operations:
- Θ(N) delete operations
- O(log N) insert operations
- O(log N) find operations
- Θ(N) decrease-key operations
To find:
The overall time complexity of all these operations put together.
Solution:
Let me analyze the time taken by each operation on a sorted doubly linked list one by one.
First, for the delete operation:
Since a direct pointer to the record to be deleted is given, we just need to update the prev and next pointers of the adjacent nodes.
Time taken for 1 delete = O(1).
Total time for Θ(N) delete operations = Θ(N) × O(1) = O(N).
Next, for the insert operation:
Since it is a linked list, we do not have random access, so we cannot do binary search. We have to scan linearly to find the correct sorted position.
Time taken for 1 insert = O(N).
Total time for O(log N) insert operations = O(log N) × O(N) = O(N log N).
Next, for the find operation:
Again, no random access, so linear search is required to find an element.
Time taken for 1 find = O(N).
Total time for O(log N) find operations = O(log N) × O(N) = O(N log N).
Now, for the decrease-key operation:
A pointer to the record is provided, but decreasing the key value means the node may no longer be in sorted order.
To restore the sorted order, we have to shift the node backwards along the list to its appropriate position.
In the worst case, shifting takes O(N) steps.
Time taken for 1 decrease-key = O(N).
Total time for Θ(N) decrease-key operations = Θ(N) × O(N) = O(N2).
Now adding up the time complexities of all operations:
Total Time = O(N) + O(N log N) + O(N log N) + O(N2)
The O(N2) term clearly dominates the entire sum.
So, the total time complexity is O(N2).
Answer:
(C) O(N2)

Ques 23 Gate 2016 Set-2


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.


(G) is the correct answer.

Given:
Floyd-Warshall algorithm for all-pair shortest paths computation.
To find:
The algorithm design paradigm it is based on.
Solution:
Let me recall how the Floyd-Warshall algorithm works.
It computes the shortest path between all pairs of vertices in a directed, weighted graph.
Let d(k)[i][j] be the shortest path from vertex i to vertex j using only intermediate vertices from the set {1, 2, ..., k}.
The recurrence relation is:
d(k)[i][j] = min(d(k-1)[i][j], d(k-1)[i][k] + d(k-1)[k][j])
This shows that the problem exhibits optimal substructure and overlapping subproblems.
We build the solution bottom-up by iteratively increasing the set of allowed intermediate vertices from k = 1 to n.
Therefore, this algorithm directly uses the Dynamic Programming approach.
Answer: (C) Dynamic Programming paradigm.

Unique Visitor Count

Total Unique Visitors

Loading......