chapter
    Algorithms PYQs for GATE CS

    GATE CS Algorithms: 1 units and 5 chapters, weightage from 47 previous year questions across 10 papers, a study order by exam weight and 10 practice questions

    A question from this chapter

    Question 1
    2026 Slot Set2 PYQ
    Consider the following functions, where is a positive integer.


    Which one of the following options lists the functions in increasing order of asymptotic growth rate?

    Note: Assume the base of log to be 2.
    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: 1 units and 5 chapters, weightage from 47 previous year questions across 10 papers, a study order by exam weight and 10 practice questions.

    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.

    GATE CS Algorithms Unit-wise Weightage from Past Papers

    We counted every GATE CS Algorithms previous year question in our bank (47 questions from 10 papers) and grouped them by unit.

    UnitChaptersPYQsShare of sectionAvg per paper
    Algorithms547100%4.7

    Suggested Algorithms Study Order for GATE CS

    1. Algorithms: 100% of past Algorithms questions, about 4.7 per paper.

    Start where the marks are. Units at the top of this list have appeared most often in past GATE CS papers.

    Units in GATE CS Algorithms

    All Algorithms chapters

    One Solved Question from Each Algorithms Chapter

    Question 1 · Asymptotic Analysis and Recurrence Relations · 2026_Set2 MCQ
    Consider the following functions, where is a positive integer.


    Which one of the following options lists the functions in increasing order of asymptotic growth rate?

    Note: Assume the base of log to be 2.
    1. A.

    2. B.

    3. C.

    4. D.

    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