chapter
    Algorithms PYQs for GATE CS

    GATE CS Algorithms: 5 chapters, 47 previous year questions (100% of Algorithms), 10 practice questions and one solved question from each chapter.

    A question from this chapter

    Question 1
    2026 Slot Set1 PYQ
    Level 3: Exam Standard
    Consider the following recurrence relations:

    For all ,


    Assume that for all , and .

    Which one of the following options is correct?
    Question 2
    2026 Slot Set2 PYQ
    Level 3: Exam Standard
    Consider an array . Suppose the merge sort algorithm is executed on array to sort it in increasing order. The merge sort algorithm will carry out a total of 7 merge operations.

    A merge operation on sorted left array and sorted right array is said to be void if the output of the merge operation is the elements of array followed by the elements of array .

    The number of void merge operations among these 7 merge operations is __________. (answer in integer)
    Question 3
    2026 Slot Set1 PYQ
    Level 3: Exam Standard
    Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph as input, where and are the discovery time and finishing time, respectively, of the vertex .


      unmark all
      
      for each
        if is unmarked
          
        end if
      end for

      mark
      
      
      for each
        if is unmarked
          
        end if
      end for
      
      
      return


    Suppose that the input directed graph is a directed acyclic graph (DAG).

    For an edge , which of the following options will NEVER be correct?
    Question 4
    2026 Slot Set2 PYQ
    Level 4: Challenger

    Let be a weighted directed acyclic graph with edges and vertices. Given and a source vertex in , which one of the following options gives the worst case time complexity of the fastest algorithm to find the lengths of shortest paths from to all vertices that are reachable from in ?

    Question 5
    2026 Slot Set2 PYQ
    Consider a table , where the elements , , represent the cost of the optimal solutions of different subproblems of a problem that is being solved using a dynamic programming algorithm. The recursive formulation to compute the table entries is as follows:



    Consider the following two algorithms to compute entries of . Assume that for both the algorithms, for all , has been initialized to .

    Algorithm : For
        For
            

    Algorithm : For
        For
            For
                If
                    

    Algorithm , is said to be correct if and only if it calculates the correct values of , for all , (as per the recursive formulation) at the end of the execution of the algorithm .

    Which one of the following statements is true?
    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Algorithms PYQs for GATE CS

    GATE CS Algorithms: 5 chapters, 47 previous year questions (100% of Algorithms), 10 practice questions and one solved question from each chapter.

    About Algorithms Previous Year Questions (PYQs)

    47 previous year questions from Algorithms in GATE CS, grouped by chapter with the exam year, answer key and step-by-step solution for each.

    Algorithms Weightage in GATE CS

    Algorithms accounts for 47 of 47 Algorithms previous year questions in our bank (100%), about 4.7 per paper across 10 papers.

    Algorithms Chapter Matrix

    ChapterTopicsPYQsShare of unit PYQsPractice questions
    Asymptotic Analysis and Recurrence RelationsSolving Recurrence Relations, Asymptotic Notation and Growth Comparison, Loop Complexity and Function Comparison1226%0
    Searching, Sorting, Selection and HashingSorting Algorithms and Operation Counts, Binary and Bitonic Array Searching, Selection and Comparison Bounds, Linear-Time Array Property Verification, Universal Hashing and Adversarial Inputs1021%10
    Graph Traversal, Connectivity and Directed GraphsBreadth-First Search Trees and Applications, Depth-First Search Edges and Timestamps, Connected Components and Articulation Points, Directed Graphs, Cycles and Strong Connectivity, Greedy Graph Coloring1021%0
    Minimum Spanning Trees and Shortest PathsMST Cut-Cycle Properties and Uniqueness, Minimum Spanning Tree Construction and Counting, Shortest-Path Properties and Algorithms, Effects of Edge-Weight Transformations1021%0
    Dynamic Programming, Greedy Algorithms and OptimizationLongest Non-Decreasing Subsequences and Array Optimization, Rod Cutting Dynamic Programming, Huffman Coding and Prefix-Free Codes, Optimal Path Computation in Directed Acyclic Graphs, Dynamic Programming Table Evaluation511%0

    More from Algorithms

    One Solved Question from Each Algorithms Chapter

    Question 1 · Asymptotic Analysis and Recurrence Relations · 2026_Set1 MCQ
    Consider the following recurrence relations:

    For all ,


    Assume that for all , and .

    Which one of the following options is correct?
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a system of recurrence relations, recognizable because depends on the solution of .

    Why this method applies: We must solve the recurrences sequentially, starting from the one that is self-contained (), find its asymptotic bound, and then substitute that bound into the other recurrence ().

    Step 1: Solve using the Master Theorem.

    Step 2: Identify . The critical exponent is .

    Step 3: Compare the driving function with . Since grows strictly slower than any positive polynomial power of , for some .

    Step 4: By Case 1 of the Master Theorem, .

    Step 5: Substitute this into the first recurrence: .

    Step 6: Apply the Master Theorem to . Here, . The critical exponent is .

    Step 7: Compare the new driving function with . Since , we have for .

    Step 8: By Case 1 of the Master Theorem again, the root dominates, so .

    Answer: Option A is correct.

    Question 2 · Searching, Sorting, Selection and Hashing · 2026_Set2 NAT
    Consider an array . Suppose the merge sort algorithm is executed on array to sort it in increasing order. The merge sort algorithm will carry out a total of 7 merge operations.

    A merge operation on sorted left array and sorted right array is said to be void if the output of the merge operation is the elements of array followed by the elements of array .

    The number of void merge operations among these 7 merge operations is __________. (answer in integer)
    Correct Answer:

    3

    Step-by-Step Solution

    Key idea: This is a merge sort operation counting question, recognisable because it asks for the number of "void" merge operations on a specific array. A void merge occurs when the left subarray's maximum element is less than or equal to the right subarray's minimum element.

    Step 1: Trace the merge sort tree for .

    Step 2: Level 3 (size 1 to 2):

    • Merge and . Not void ().
    • Merge and . Void (). (Count = 1)
    • Merge and . Not void ().
    • Merge and . Void (). (Count = 2)

    Step 3: Level 2 (size 2 to 4):

    • Merge and . Not void ().
    • Merge and . Not void ().

    Step 4: Level 1 (size 4 to 8):

    • Merge and . Void (). (Count = 3)

    Step 5: Total void merges = 3.

    Answer: 3

    Question 3 · Graph Traversal, Connectivity and Directed Graphs · 2026_Set1 MSQ
    Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph as input, where and are the discovery time and finishing time, respectively, of the vertex .


      unmark all
      
      for each
        if is unmarked
          
        end if
      end for

      mark
      
      
      for each
        if is unmarked
          
        end if
      end for
      
      
      return


    Suppose that the input directed graph is a directed acyclic graph (DAG).

    For an edge , which of the following options will NEVER be correct?
    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    ["B","D"]

    Step-by-Step Solution

    Key idea: This is a "DFS timestamp and DAG properties" question, recognisable because it asks which timestamp relationships are impossible for an edge in a Directed Acyclic Graph.

    Step 1: Understand the Parenthesis Theorem.

    For any two vertices and in a DFS traversal, their discovery/finish intervals and must be either completely disjoint or perfectly nested. They can never partially overlap.

    Step 2: Evaluate Option D.

    represents partially overlapping intervals. This violates the Parenthesis Theorem and is impossible in ANY DFS traversal, regardless of whether the graph is a DAG. Thus, Option D will NEVER be correct.

    Step 3: Evaluate Option B.

    represents perfectly nested intervals where is an ancestor of . This means the edge goes from a descendant to an ancestor, which is the definition of a back edge. A back edge implies the existence of a cycle. Since the input graph is a DAG (Directed Acyclic Graph), it cannot contain any cycles, and therefore cannot contain any back edges. Thus, Option B will NEVER be correct.

    Step 4: Evaluate Options A and C.

    Option A () represents nested intervals where is an ancestor of . This corresponds to a tree edge or forward edge, which are perfectly valid in a DAG.

    Option C () represents disjoint intervals where is completely finished before is discovered. This corresponds to a cross edge, which is also valid in a DAG.

    Answer: B, D

    Question 4 · Minimum Spanning Trees and Shortest Paths · 2026_Set2 MCQ

    Let be a weighted directed acyclic graph with edges and vertices. Given and a source vertex in , which one of the following options gives the worst case time complexity of the fastest algorithm to find the lengths of shortest paths from to all vertices that are reachable from in ?

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: Shortest paths in a Directed Acyclic Graph (DAG) can be found in linear time using topological sorting.

    Step 1: Recognize that the graph is a DAG. This is the crucial condition that allows a faster algorithm than Dijkstra's or Bellman-Ford.

    Step 2: Perform a topological sort of the vertices. This takes time using DFS or Kahn's algorithm.

    Step 3: Initialize the distance to the source vertex as 0, and all other vertices as .

    Step 4: Process each vertex in topological order. For each outgoing edge with weight , relax the edge: if , update .

    Step 5: Since each vertex and each edge is processed exactly once in the topological order, the relaxation step takes time.

    Answer:

    Question 5 · Dynamic Programming, Greedy Algorithms and Optimization · 2026_Set2 MCQ
    Consider a table , where the elements , , represent the cost of the optimal solutions of different subproblems of a problem that is being solved using a dynamic programming algorithm. The recursive formulation to compute the table entries is as follows:



    Consider the following two algorithms to compute entries of . Assume that for both the algorithms, for all , has been initialized to .

    Algorithm : For
        For
            

    Algorithm : For
        For
            For
                If
                    

    Algorithm , is said to be correct if and only if it calculates the correct values of , for all , (as per the recursive formulation) at the end of the execution of the algorithm .

    Which one of the following statements is true?
    1. A.

      Both algorithms and are correct

    2. B.

      Algorithm is correct, but algorithm is incorrect

    3. C.

      Algorithm is correct, but algorithm is incorrect

    4. D.

      Both algorithms and are incorrect