GATE / CS ARCHIVE

SUBJECT COLLECTION

Algorithms · Other / Mixed Topics

6 questions, newest first

Browse topics
1 mark · MCQ
Report issue

Other / Mixed Topics

Question 5, GATE 2017: Match P Kruskal, Q Quicksort, R Floyd–Warshall to i divide and conquer, ii greedy, iii dynamic programming. 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.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

1. Kruskal sorts edges by weight and repeatedly accepts a cheapest edge that does not form a cycle. This is the greedy paradigm ii.

2. Quicksort partitions around a pivot, recursively sorts the two resulting parts, and combines their order: divide and conquer i.

3. Floyd–Warshall updates distances by allowing intermediate vertices one at a time: Dk[i,j]=min(Dk−1[i,j],Dk−1[i,k]+Dk−1[k,j]). Reused subproblem values make it dynamic programming iii. Thus C.

Original paper, page 4 · Answer key

1 mark · MCQ
Report issue

Other / Mixed Topics

Question 13, GATE 2015: Match algorithms P Prim MST, Q Floyd–Warshall all-pairs shortest paths, R mergesort, S Hamiltonian circuit search with i backtracking, ii greedy, iii dynamic programming, 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.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Prim greedily adds a cheapest edge crossing the current tree's cut. Floyd–Warshall builds shortest paths by increasing the allowed intermediate vertices, a dynamic-programming recurrence. Mergesort solves two smaller sorting problems and merges their answers. A standard Hamiltonian-circuit search tries vertices and abandons partial paths that cannot extend, illustrating backtracking.

Solution: Prim uses greedy selection; Floyd–Warshall uses dynamic programming; mergesort uses divide and conquer; the standard Hamiltonian-circuit search uses backtracking. Thus P-ii, Q-iii, R-iv, S-i, C.

Original paper, page 7 · Answer key

2 marks · MCQ
Report issue

Other / Mixed Topics

Question 47, GATE 2015: Match algorithms 1Dijkstra, 2Floyd–Warshall, 3 binary search, 4 backtracking with i divide/conquer, ii dynamic programming, iii greedy, iv DFS, v BFS. A1i2 iii 3i4v; B1 iii 2 iii 3i4v; C1 iii 2 ii 3i4 iv; D1 iii 2 ii 3i4v.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Dijkstra uses greedy finalization; Floyd–Warshall uses dynamic programming; binary search divides the search interval; backtracking explores depth first. Hence 1-iii, 2-ii, 3-i, 4-iv, C.

Dijkstra commits the currently smallest tentative distance using a greedy safe-choice argument. Floyd–Warshall improves paths by allowing successively larger sets of intermediate vertices, which is dynamic programming. Binary search reduces the search interval to one half, matching divide-and-conquer here. Backtracking explores one partial-choice path before undoing it and trying another, so its traversal is depth-first rather than breadth-first. The complete matching is 1 iii, 2 ii, 3i, 4 iv.

Original paper, page 42 · Answer key

Descriptive
Report issue

Locate point below line

Other / Mixed Topics

Question 14(a), GATE 2000: Let m,n be positive integers and let the line be y=(n/m)x. Define A=mq−np for endpoint (p,q), and B=ms−nr for endpoint (r,s). If A<0, is (p,q) above, below or on the line?
Question 14(a), GATE 2000: Let m,n be positive integers and let the line be y=(n/m)x. Define A=mq−np for endpoint (p,q), and B=ms−nr for endpoint (r,s). If A<0, is (p,q) above, below or on the line?
Tap to enlarge
Answer & solution

Answer: Below the line. (no official key was published)

Because m>0, dividing mq−np<0 by m preserves the inequality and gives q<(n/m)p. At horizontal coordinate p, the line has height (n/m)p, whereas the point has smaller height q. Therefore the point is below the line. Equality A=0 would mean on the line, and A>0 would mean above. The assumption m>0 is essential when converting the sign to this vertical interpretation.

Original paper, page 8

1 mark · MCQ
Report issue

Counting substring occurrences

Other / Mixed Topics

Question 1.23, GATE 1998: How many nonempty substrings of all lengths can be formed from a length-n string? Choices include n, n², 2^n, n (n+1)/2.
Tap to enlarge
Your answer
Answer & solution

Answer: D for positional occurrences (no official key was published)

A substring is determined by its starting and ending positions. For length k there are n−k+1 placements. Summing these counts from k=1 to n gives n+(n−1)+…+1=n (n+1)/2, D. This counts occurrences, even when their text is identical. If the phrase “different lengths” means counting length values alone, there are only n; if it means distinct substring contents, the answer depends on the string. The standard occurrence interpretation is explicitly used.

Original paper, page 2

1 mark · MCQ
Report issue

Matching algorithm paradigms

Other / Mixed Topics

Question 1.5, GATE 1997: Match all-pairs shortest paths, quicksort, minimum spanning tree, connected components with dynamic programming, divide-and-conquer, greedy, DFS.
Question 1.5, GATE 1997: Match all-pairs shortest paths, quicksort, minimum spanning tree, connected components with dynamic programming, divide-and-conquer, greedy, DFS.
Tap to enlarge
Your answer
Answer & solution

Answer: B: 3, 4, 1, 2 (no official key was published)

Floyd–Warshall solves all-pairs paths through dynamic-programming subproblems. Quicksort partitions around a pivot and recursively sorts subarrays, a divide-and-conquer strategy. Prim or Kruskal builds an MST using safe greedy edge choices. Repeated DFS visits each connected component. Thus the four matches are 3, 4, 1, 2, option B. These refer to standard representative algorithms rather than asserting that each task has only one possible solution paradigm.

Original paper, page 1