🇮🇳 GATE CS & IT Engineering · subject
GATE CS & IT Engineering Algorithms Syllabus
The Algorithms syllabus for GATE CS & IT Engineering in full: 8 chapters and 17 topics, every one listed below, plus 51 Algorithms flashcards with answers.
Algorithms syllabus: all 8 chapters
Expand any chapter to see its topics and sub-topics.
-
Searching
2 topics- Linear Search
- Binary Search
-
Sorting
2 topics- Bubble Sort
- Merge Sort
-
Hashing
2 topics- Hash Functions
- Collision Handling
-
Asymptotic worst case time and space complexity
2 topics- Time Complexity
- Space Complexity
-
Algorithm design techniques
3 topics- Greedy
- Dynamic Programming
- Divide-and-Conquer
-
Graph Traversals
2 topics- Breadth First Search (BFS)
- Depth First Search (DFS)
-
Minimum Spanning Trees
2 topics- Kruskal's Algorithm
- Prim's Algorithm
-
Shortest Paths
2 topics- Dijkstra's Algorithm
- Bellman-Ford Algorithm
GATE CS & IT Engineering Algorithms flashcards — 51 questions with answers
What is Linear Search and what is its worst-case and average-case time complexity?
Linear Search scans elements one by one from the start until the target is found or the list ends. It works on unsorted data. Worst-case and average-case time complexity are both $O(n)$; best case is $O(1)$.
State the precondition for Binary Search and its time complexity.
The array must be sorted. Binary Search repeatedly halves the search interval, comparing the target to the middle element. Time complexity is $O(\log n)$ in the worst and average case, $O(1)$ best case.
Write the recurrence relation for Binary Search and its solution.
$$T(n) = T\!\left(\frac{n}{2}\right) + O(1)$$ which solves to $T(n) = O(\log n)$.
In Binary Search, how is the middle index computed safely to avoid integer overflow?
Use $mid = low + \frac{high - low}{2}$ instead of $mid = \frac{low + high}{2}$, since the latter can overflow for large $low + high$.
Describe how Bubble Sort works.
Bubble Sort repeatedly steps through the list, comparing adjacent elements and swapping them if they are out of order. After each pass the largest unsorted element 'bubbles' to its correct position. It repeats until no swaps are needed.
State the worst-case, average-case, and best-case time complexity of Bubble Sort.
Worst and average case: $O(n^{2})$. Best case (already sorted, with optimization): $O(n)$. Space complexity: $O(1)$.
Is Bubble Sort stable and in-place? Why does stability matter?
Bubble Sort is both stable (equal elements keep their relative order, since it only swaps strictly out-of-order adjacent pairs) and in-place ($O(1)$ extra space). Stability matters when sorting records by a secondary key.
Describe the Merge Sort algorithm and its paradigm.
Merge Sort is a divide-and-conquer algorithm: it splits the array into two halves, recursively sorts each half, then merges the two sorted halves into one sorted array.
Write the recurrence relation for Merge Sort and its solution.
$$T(n) = 2T\!\left(\frac{n}{2}\right) + O(n)$$ which by the Master Theorem solves to $T(n) = O(n \log n)$.
State the time and space complexity of Merge Sort, and whether it is stable.
Time complexity is $O(n \log n)$ in all cases (best, average, worst). Space complexity is $O(n)$ for the auxiliary array. Merge Sort is stable.
In Merge Sort, what is the time complexity of the merge step for two sorted lists of total size $n$?
The merge step runs in $O(n)$ time, since each element is compared and placed exactly once using two pointers.
What is a hash function, and what are the two essential properties of a good one?
A hash function maps a key to an index in a hash table. A good hash function should be (1) deterministic and fast to compute, and (2) distribute keys uniformly to minimize collisions.
What is the division method of hashing? Give its formula.
The division method computes $h(k) = k \bmod m$, where $m$ is the table size. Choosing $m$ as a prime not close to a power of 2 helps spread keys uniformly.
State the multiplication method of hashing.
$$h(k) = \lfloor m \,(k A \bmod 1) \rfloor$$ where $0 < A < 1$ is a constant (Knuth suggests $A \approx \frac{\sqrt{5}-1}{2} \approx 0.6180$) and $k A \bmod 1$ is the fractional part of $kA$.
What is a collision in hashing?
A collision occurs when two distinct keys $k_1 \neq k_2$ hash to the same index, i.e. $h(k_1) = h(k_2)$.
Name the two broad strategies for collision handling.
(1) Separate chaining (each slot holds a linked list/bucket of entries), and (2) open addressing (probing for another empty slot within the table).
Define the load factor of a hash table and give its formula.
The load factor measures how full the table is: $$\alpha = \frac{n}{m}$$ where $n$ is the number of stored elements and $m$ is the number of slots.
What is linear probing, and what problem does it cause?
Linear probing resolves collisions by checking the next slots sequentially: $h(k, i) = (h'(k) + i) \bmod m$. It causes primary clustering, where long runs of occupied slots form and degrade performance.
Write the probe sequence for quadratic probing and the problem it addresses.
$$h(k, i) = \left(h'(k) + c_1 i + c_2 i^{2}\right) \bmod m$$ It reduces primary clustering but suffers from secondary clustering (keys with the same initial hash follow the same probe sequence).
Write the double hashing probe sequence.
$$h(k, i) = \left(h_1(k) + i \cdot h_2(k)\right) \bmod m$$ where $h_2(k)$ must never be $0$ and should be relatively prime to $m$. Double hashing minimizes clustering.
Show the other 31 Algorithms flashcards
In separate chaining, what is the expected search time under simple uniform hashing?
Expected time is $O(1 + \alpha)$, where $\alpha$ is the load factor. With $\alpha = O(1)$ (table size proportional to $n$), search, insert, and delete are $O(1)$ on average.
Define time complexity (asymptotic) and what Big-O notation represents.
Time complexity describes how an algorithm's running time grows with input size $n$. Big-O, $O(f(n))$, gives an asymptotic upper bound: $T(n) = O(f(n))$ if $T(n) \leq c \cdot f(n)$ for some constant $c > 0$ and all $n \geq n_0$.
Define Big-Omega $\Omega$ and Big-Theta $\Theta$ notation.
$\Omega(f(n))$ is an asymptotic lower bound: $T(n) \geq c f(n)$ for large $n$. $\Theta(f(n))$ is a tight bound: $T(n) = \Theta(f(n))$ iff $T(n) = O(f(n))$ and $T(n) = \Omega(f(n))$ simultaneously.
Order these common complexities from fastest- to slowest-growing: $O(n^{2})$, $O(1)$, $O(n \log n)$, $O(2^{n})$, $O(\log n)$, $O(n)$.
$$O(1) < O(\log n) < O(n) < O(n \log n) < O(n^{2}) < O(2^{n})$$
State the Master Theorem for recurrences of the form $T(n) = aT(n/b) + f(n)$.
Let $c = \log_b a$. Then: (1) if $f(n) = O(n^{c-\epsilon})$, $T(n) = \Theta(n^{c})$; (2) if $f(n) = \Theta(n^{c})$, $T(n) = \Theta(n^{c} \log n)$; (3) if $f(n) = \Omega(n^{c+\epsilon})$ and regularity holds, $T(n) = \Theta(f(n))$.
Define space complexity and distinguish auxiliary space from total space.
Space complexity is the total memory an algorithm uses as a function of input size $n$. Total space = input space + auxiliary space; auxiliary space is the extra/temporary space used beyond the input itself.
What is the space complexity of a recursive algorithm with recursion depth $d$?
At least $O(d)$ due to the call stack, where $d$ is the maximum recursion depth. For example, recursive Binary Search uses $O(\log n)$ stack space.
Describe the greedy algorithm paradigm and the two properties a problem must have for it to be optimal.
A greedy algorithm builds a solution by making the locally optimal choice at each step. For correctness it needs (1) the greedy-choice property (a global optimum can be reached by local choices) and (2) optimal substructure.
Give two classic problems solvable optimally by greedy algorithms.
Examples: Activity Selection (interval scheduling), Huffman coding, Fractional Knapsack, and minimum spanning tree algorithms (Kruskal's, Prim's). Note: 0/1 Knapsack is NOT solved optimally by greedy.
Why does the greedy approach fail for the 0/1 Knapsack problem but work for Fractional Knapsack?
In Fractional Knapsack you can take fractions, so choosing highest value-to-weight ratio first is optimal. In 0/1 Knapsack items are indivisible, so the greedy ratio choice can be suboptimal; it requires dynamic programming instead.
Define dynamic programming and the two properties a problem must satisfy to use it.
Dynamic programming solves problems by combining solutions to overlapping subproblems, storing each subproblem result to avoid recomputation. It requires (1) optimal substructure and (2) overlapping subproblems.
Distinguish memoization (top-down) from tabulation (bottom-up) in dynamic programming.
Memoization is top-down recursion that caches results as subproblems are encountered. Tabulation is bottom-up, iteratively filling a table from base cases upward. Both avoid recomputation; tabulation avoids recursion overhead.
What are the time and space complexities of the classic 0/1 Knapsack DP with $n$ items and capacity $W$?
Time complexity is $O(nW)$ and space complexity is $O(nW)$ (reducible to $O(W)$ with a 1D array). This is pseudo-polynomial since $W$ is a numeric value, not the input size in bits.
How does dynamic programming differ from divide-and-conquer?
Both break problems into subproblems, but divide-and-conquer subproblems are independent (non-overlapping), while DP subproblems overlap and their solutions are stored/reused. Merge Sort is divide-and-conquer; Fibonacci with memoization is DP.
State the three steps of the divide-and-conquer paradigm.
(1) Divide the problem into smaller subproblems; (2) Conquer each subproblem by solving it recursively; (3) Combine the subproblem solutions into the solution for the original problem.
Give the recurrence and complexity of finding both min and max using divide-and-conquer.
$$T(n) = 2T\!\left(\frac{n}{2}\right) + 2$$ which yields about $\frac{3n}{2} - 2$ comparisons, i.e. $O(n)$ time.
Describe Breadth First Search (BFS), the data structure it uses, and its order of visiting.
BFS explores a graph level by level from a source, visiting all neighbors at the current depth before moving deeper. It uses a queue (FIFO) and marks vertices visited to avoid revisiting.
State the time and space complexity of BFS on a graph with $V$ vertices and $E$ edges.
Time complexity is $O(V + E)$ using adjacency lists. Space complexity is $O(V)$ for the queue and visited array.
What key property does BFS guarantee in an unweighted graph?
BFS finds the shortest path (minimum number of edges) from the source to every reachable vertex in an unweighted graph.
Describe Depth First Search (DFS), the data structure it uses, and its strategy.
DFS explores as far as possible along each branch before backtracking. It uses a stack (explicit, or implicit via recursion) and marks vertices visited. Time complexity $O(V+E)$, space $O(V)$.
Name three classic applications of DFS.
Topological sorting of a DAG, detecting cycles in a graph, finding connected components / strongly connected components, and classifying edges (tree, back, forward, cross).
What does Kruskal's algorithm compute, and what is its greedy strategy?
Kruskal's algorithm finds a Minimum Spanning Tree (MST). It sorts all edges by weight ascending and adds the next smallest edge that does not form a cycle, using a Union-Find (disjoint-set) structure to detect cycles.
State the time complexity of Kruskal's algorithm.
$O(E \log E)$ (or equivalently $O(E \log V)$) dominated by sorting the edges; the Union-Find operations add nearly $O(E \,\alpha(V))$ where $\alpha$ is the inverse Ackermann function.
What does Prim's algorithm compute, and what is its greedy strategy?
Prim's algorithm finds a Minimum Spanning Tree. It grows the MST from a starting vertex, repeatedly adding the minimum-weight edge that connects a vertex in the tree to a vertex outside it.
State the time complexity of Prim's algorithm with a binary heap versus an adjacency matrix.
With a binary heap and adjacency list: $O(E \log V)$. With an adjacency matrix (simple array): $O(V^{2})$. With a Fibonacci heap: $O(E + V \log V)$.
Compare when to prefer Kruskal's versus Prim's algorithm.
Kruskal's ($O(E \log E)$) is better for sparse graphs (few edges). Prim's with an adjacency matrix ($O(V^{2})$) is better for dense graphs (many edges). Both produce a correct MST.
What problem does Dijkstra's algorithm solve, and what is its key restriction?
Dijkstra's computes single-source shortest paths in a weighted graph. Its key restriction is that all edge weights must be non-negative; it fails with negative edges.
State the time complexity of Dijkstra's algorithm with a binary heap and with a Fibonacci heap.
With a binary min-heap: $O((V + E)\log V)$, often written $O(E \log V)$. With a Fibonacci heap: $O(E + V \log V)$.
What is the greedy relaxation step in Dijkstra's algorithm?
For an edge $(u,v)$ with weight $w$, relaxation updates: if $d[u] + w(u,v) < d[v]$, set $d[v] = d[u] + w(u,v)$. Dijkstra repeatedly extracts the unvisited vertex with smallest $d$ and relaxes its edges.
What problem does the Bellman-Ford algorithm solve, and what advantage does it have over Dijkstra's?
Bellman-Ford computes single-source shortest paths and, unlike Dijkstra's, handles negative edge weights. It can also detect negative-weight cycles reachable from the source.
State the time complexity of Bellman-Ford and how it detects a negative cycle.
Time complexity is $O(V \cdot E)$: it relaxes all $E$ edges $V-1$ times. To detect a negative cycle, it performs one more relaxation pass; if any distance can still be reduced, a negative-weight cycle exists.
GATE CS & IT Engineering Algorithms FAQ
What is in the GATE CS & IT Engineering Algorithms syllabus?
GATE CS & IT Engineering Algorithms is split into 8 chapters: Searching, Sorting, Hashing, Asymptotic worst case time and space complexity, Algorithm design techniques, Graph Traversals, Minimum Spanning Trees and Shortest Paths. Together they contain 17 topics.
How many chapters are in GATE CS & IT Engineering Algorithms?
8 chapters, containing 17 topics. The largest chapter is Algorithm design techniques, with 3 topics.
Are there flashcards for GATE CS & IT Engineering Algorithms?
Yes — a 51-card Algorithms deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.