chapter
    Algorithms Practice Questions for GATE DA

    GATE DA Algorithms: 6 chapters, 14 previous year questions (45% of Programming, Data Structures and Algorithms), 752 practice questions and one solved questio

    A question from this chapter

    Question 1
    Level 3: Exam Standard

    Consider a binary search implementation where each step performs exactly one comparison to check equality, and if false, a second comparison to check less-than. Let be the maximum number of comparisons for an array of size . Which of the following statements is/are TRUE?

    I. is a non-decreasing function of .

    II. for all .

    III. If , then must be exactly 64.

    IV. for all .

    Question 2
    Level 3: Exam Standard

    Four arrays of distinct integers are given below. Consider the standard (non-optimized) Bubble Sort and the standard Selection Sort applied to each array until fully sorted. Which ONE of the following statements is IMPOSSIBLE?

    Question 3
    Level 3: Exam Standard
    Assertion (A): For an array of size sorted in ascending order, the standard Lomuto partition scheme (with the last element as pivot) performs exactly 0 actual data movements (swaps where the source and destination indices differ).
    Reason (R): The algorithm executes exactly swap statements, and each of these statements corresponds to a distinct data movement that places an element into a new index.
    Question 4
    Level 3: Exam Standard

    Let be a directed graph. A depth-first search from a source vertex in discovers exactly 12 vertices (including ). A depth-first search from in the reverse graph discovers exactly 18 vertices (including ). If the strongly connected component containing has exactly 7 vertices, what is the number of vertices in that can reach , but are not reachable from ?

    Question 5
    Level 3: Exam Standard

    Suppose we run Kahn's algorithm on a directed graph with 15 vertices. The algorithm terminates with 11 vertices in the topological sort list, and the queue becomes empty. What is the minimum number of edges that must be removed from the graph to make it a Directed Acyclic Graph?

    Question 6
    Level 3: Exam Standard

    Consider the array of length .

    Let denote the length of the longest contiguous non-decreasing subarray that ends exactly at index (1-indexed). The recurrence is:

    What is the maximum value in the array ?

    Free preview ends here

    Login to view the complete practice 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 Practice Questions for GATE DA

    GATE DA Algorithms: 6 chapters, 14 previous year questions (45% of Programming, Data Structures and Algorithms), 752 practice questions and one solved question from each chapter.

    About Algorithms Practice Questions

    752 practice questions for Algorithms in GATE DA, sorted chapter by chapter and graded from basic to exam level, each with a full solution.

    Algorithms Weightage in GATE DA

    Algorithms accounts for 14 of 31 Programming, Data Structures and Algorithms previous year questions in our bank (45%), about 4.7 per paper across 3 papers.

    Algorithms Chapter Matrix

    ChapterTopicsPYQsShare of unit PYQsPractice questions
    Searching Algorithms and Binary SearchBinary Search Recurrence and Worst-Case Comparisons, Binary Search Preconditions and Data Representation321%157
    Elementary Sorting AlgorithmsBubble, Insertion and Selection Sort Pass Analysis, Insertion Sort Swaps and Nearly Sorted Arrays321%160
    Quicksort and Divide-and-Conquer AnalysisQuicksort Partitioning and Swap Count, Expected Recurrence Analysis of Randomized Quicksort214%118
    Graph Traversal: BFS and DFSReachability in Directed Graph Traversals, DFS Discovery Order and Edge Classification, Graph Traversal on Given Diagrams429%210
    Directed Acyclic Graphs and Topological OrderingTopological Ordering of DAGs17%52
    Dynamic Programming and Sequence ProcessingDynamic Programming for Consecutive Sequence Lengths17%55

    More from Programming, Data Structures and Algorithms

    One Solved Question from Each Algorithms Chapter

    Question 1 · Searching Algorithms and Binary Search MSQ

    Consider a binary search implementation where each step performs exactly one comparison to check equality, and if false, a second comparison to check less-than. Let be the maximum number of comparisons for an array of size . Which of the following statements is/are TRUE?

    I. is a non-decreasing function of .

    II. for all .

    III. If , then must be exactly 64.

    IV. for all .

    1. A.

      I and IV only

    2. B.

      I and III only

    3. C.

      II and IV only

    4. D.

      I, II and IV only

    Correct Answer:

    ["A"]

    Step-by-Step Solution

    Key idea: . Analyze each statement using the properties of the floor function and logarithms.

    Step 1: Statement I: As increases, is non-decreasing, so is non-decreasing. True.

    Step 2: Statement II: . . They are not equal. False.

    Step 3: Statement III: . is not necessarily exactly 64. False.

    Step 4: Statement IV: We know for all integers . Thus , which means is true (it is actually an equality).

    Answer: I and IV only (Option A).

    Question 2 · Elementary Sorting Algorithms MSQ

    Four arrays of distinct integers are given below. Consider the standard (non-optimized) Bubble Sort and the standard Selection Sort applied to each array until fully sorted. Which ONE of the following statements is IMPOSSIBLE?

    1. A.

      Bubble Sort on P makes more comparisons than Bubble Sort on Q

    2. B.

      Selection Sort on P and Selection Sort on Q make the same number of comparisons

    3. C.

      Bubble Sort on Q makes fewer comparisons than Selection Sort on Q

    4. D.

      Insertion Sort on R makes fewer comparisons than Selection Sort on R

    Correct Answer:

    ["A","C"]

    Step-by-Step Solution

    Key idea: this is a comparison-count invariance question — recognisable because it contrasts algorithms whose counts depend on data (Bubble, Insertion) against one whose count never depends on data (Selection).

    Step 1: Establish the rules.

    • Standard Bubble Sort (no early termination): always comparisons for full sort. For : .
    • Standard Selection Sort: always comparisons, invariant to data. For : .
    • Insertion Sort: comparisons depend on data; minimum (sorted), maximum (reverse).

    Step 2: Evaluate each statement.

    • A: Bubble on P vs Bubble on Q — both are (fixed). So "more" is FALSE. → impossible-looking claim but we test truth of the option text; A states a strict inequality that is false. Wait — re-read: A claims BS(P) > BS(Q). Since both equal 10, A is FALSE.
    • B: SS(P) = SS(Q) = 10 → TRUE.
    • C: BS(Q)=10 vs SS(Q)=10 → "fewer" is FALSE.
    • D: IS(R): trace gives 8 comparisons; SS(R)=10 → "fewer" TRUE.

    Hold on — the question asks which statements are IMPOSSIBLE (i.e., false). Re-examine carefully:

    • A (BS(P)>BS(Q)): both 10 → false → IMPOSSIBLE.
    • B (SS(P)=SS(Q)): true → possible.
    • C (BS(Q)<SS(Q)): both 10 → false → IMPOSSIBLE.
    • D (IS(R)<SS(R)): 8<10 → true → possible.

    Therefore the impossible statements are A and C.

    Verification via tracing:

    • BS(Q): pass counts 4+3+2+1 = 10. ✓
    • SS(Q): scans unsorted suffix each pass: 4+3+2+1 = 10. ✓
    • IS(R)=[3,1,2,4,5]: insert 1 (compares with 3 →1 comp+shift... let's trust trace = 8). ✓ < 10.

    Tempting wrong path: students often think optimized Bubble Sort stops early on already-sorted Q, giving 4 comparisons, making C "true". But the statement specifies STANDARD (non-optimized) Bubble Sort, so no early stop — Q still costs 10. That unit/condition mismatch flips C.

    Generalization: Selection Sort's comparison count is a constant for every input; only Insertion Sort (and optimized Bubble) vary with data.

    Answer: A and C are impossible.

    Question 3 · Quicksort and Divide-and-Conquer Analysis MCQ
    Assertion (A): For an array of size sorted in ascending order, the standard Lomuto partition scheme (with the last element as pivot) performs exactly 0 actual data movements (swaps where the source and destination indices differ).
    Reason (R): The algorithm executes exactly swap statements, and each of these statements corresponds to a distinct data movement that places an element into a new index.
    1. A.

      Both A and R are true, and R is the correct explanation of A.

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A.

    3. C.

      A is true, but R is false.

    4. D.

      A is false, but R is true.

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: Distinguish between the execution of a swap statement and an actual data movement. A self-swap () executes the statement but moves 0 elements.

    Exam route: In an already sorted array with Lomuto, the boundary pointer always equals the scanning pointer . Thus, all swap statements are self-swaps.

    Learning route:

    Step 1: Lomuto partition on a sorted array with the last element as pivot.

    Step 2: For each from to , is true.

    Step 3: increments, so becomes equal to . The swap A[i] with A[j] is a self-swap (0 data movements).

    Step 4: After the loop, . The final swap is A[i+1] with A[high], which is A[high] with A[high], another self-swap.

    Step 5: Total actual data movements = 0. Assertion A is true.

    Step 6: Reason R claims each of the swap statements corresponds to a distinct data movement. This is false, as they are all self-swaps.

    Answer: A is true, but R is false.

    Common trap: Unit mismatch. Confusing the count of swap statement executions () with the count of actual data movements (0), leading to the belief that A is false.

    Question 4 · Graph Traversal: BFS and DFS MCQ

    Let be a directed graph. A depth-first search from a source vertex in discovers exactly 12 vertices (including ). A depth-first search from in the reverse graph discovers exactly 18 vertices (including ). If the strongly connected component containing has exactly 7 vertices, what is the number of vertices in that can reach , but are not reachable from ?

    1. A.

      5

    2. B.

      11

    3. C.

      6

    4. D.

      12

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: The set of vertices that can reach is exactly the forward reachable set of in the reverse graph .

    Step 1: Let be the set of vertices reachable from in . We are given .

    Step 2: Let be the set of vertices that can reach in . This is equivalent to the forward reachable set of in . We are given .

    Step 3: The strongly connected component (SCC) containing is the intersection . We are given its size is 7.

    Step 4: We need to find the number of vertices that can reach but are not reachable from . This is the set .

    Step 5: The size of this set is .

    Answer: 11.

    Question 5 · Directed Acyclic Graphs and Topological Ordering MCQ

    Suppose we run Kahn's algorithm on a directed graph with 15 vertices. The algorithm terminates with 11 vertices in the topological sort list, and the queue becomes empty. What is the minimum number of edges that must be removed from the graph to make it a Directed Acyclic Graph?

    1. A.

      4

    2. B.

      1

    3. C.

      11

    4. D.

      15

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a casework question about Kahn's algorithm termination and hidden cycles.

    Step 1: Kahn's algorithm processes vertices with in-degree 0. If it terminates with 11 vertices processed out of 15, it means 4 vertices are left unprocessed.

    Step 2: The 4 unprocessed vertices must have in-degrees > 0 from each other, meaning the subgraph induced by these 4 vertices contains at least one cycle.

    Step 3: To make the graph a DAG, we must break all cycles. The minimum number of edges to remove to break a cycle in a subgraph of 4 vertices is 1 (e.g., if they form a simple 4-cycle, or a 3-cycle with a tail attached).

    Step 4: Thus, the minimum number of edges to remove is 1.

    Step 5: Address the trap. The unit_mismatch trap occurs when students answer 4 (the number of unprocessed vertices) or 11 (the number of processed vertices), confusing the unit of "vertices" with "edges".

    Answer: 1

    Question 6 · Dynamic Programming and Sequence Processing MCQ

    Consider the array of length .

    Let denote the length of the longest contiguous non-decreasing subarray that ends exactly at index (1-indexed). The recurrence is:

    What is the maximum value in the array ?

    1. A.

      4

    2. B.

      5

    3. C.

      6

    4. D.

      13

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: The maximum value in represents the length of the longest non-decreasing contiguous subarray in the entire array. We need to trace and find its maximum.

    Step 1: Trace the DP array.

    : .

    : . Extend. .

    : . Extend. .

    : . Extend. .

    : . Reset. .

    : . Extend. .

    : . Extend. .

    : . Extend. .

    : . Extend. .

    : . Reset. .

    : . Extend. .

    : . Extend. .

    : . Extend. .

    Step 2: Find the maximum.

    .

    Maximum value is 5 (at ).

    Answer: 5.