Question
Question
Introduction to Algorithms
1. What do you mean by algorithms? State some application areas of
algorithms.
2. What is the closet pair problem? Write an algorithm to solve the problem
using the divide and conquer paradigm.
2. Asymptotic Notations
1. Define algorithm. Write down the properties of good algorithms. Why is
choosing an appropriate data structure for an algorithm important?
• 2n² + 5n = O(n²)
• n² × log n = O(n²)
• n³ + 10n² = O(n²)
• n × 2� = O(3�)
1
6. Prove that any comparison sort algorithm requires Ω(n log n) comparisons
in the worst case.
8. Let T(n) = ½n³ + 3n. Which of the following statements are true?
(i) T(n)=O(n), (ii) T(n)=Θ(n³), (iii) T(n)=O(n³), (iv) T(n)=Ω(n³).
3. Sorting Algorithms
1. Write a short note on the Brute force technique.
3. Write the pseudocode for the Insertion sort algorithm with examples.
State best, worst, and average time complexities.
6. Write down the pseudocode of bucket sort and prove that the time
complexity is linear.
7. Show the average-case time complexity for quick sort using the recursion
tree method.
8. Calculate the average and best-case complexities of quick sort using the
recursion method.
2
12. A sorting method is said to be stable if identical elements remain in the
same order as in the original set. Is merge sort a stable sorting method?
2. Write down the pseudocode for the merge sort algorithm using divide
and conquer. Calculate its time complexity using the substitution method.
• T(n) = 4T(n/2) + n
• T(n) = 16T(n/4) + n²
4. Write the merits and demerits of the substitution method and the Master
Theorem.
6. Write the pseudocode for the binary search algorithm and establish its
recurrence relation.
5. Dynamic Programming
1. What properties suggest that a problem can be solved using Dynamic
Programming?
2. Define the Subset Sum problem (SSS). Write the recursive formula.
Construct a DP table and track elements for a given input set and target
3
sum.
4. Find the longest common subsequence from the given two sequences of
characters.
6. Greedy Algorithms
1. You are given a list of activities with start and finish times. Apply
a greedy approach to select the maximum number of non-overlapping
activities.
2. A thief enters a shop with a backpack capacity of 6 kg. Four products (with
weight and profit) are given. The thief uses a greedy approach based on
profit-per-kg to maximize profit.
5. There are N children in a line, each with a “rating.” You must give candies
such that:
• Each child gets at least one candy.
4
• What is the minimum number of candies needed?
• Optimal solution
7. Graph Algorithms
1. What is a spanning tree of a graph? Write Kruskal’s algorithm to find
a minimum spanning tree (MST) of a weighted graph. Analyze time
complexity with appropriate data structures.
5
3. Suppose you need to store a sparse graph in memory. Which data
structure is best? Explain with pros and cons.
4. What is the difference between BFS and DFS? Write the pseudocode for
DFS and trace it completely.
6
8. Run either Kruskal’s or Prim’s MST algorithm on the graph in Fig. 7(b).
If needed, start from vertex A. Write down the pseudo code and label
edges 1,2,3… as they are chosen.
11. Find the shortest path from node S in the graph of Fig. 6(c) using
Bellman–Ford. Derive the result up to i=3 edges.
7
12. How many ways are there to represent a graph? Describe them with
pros and cons. Why are stack and queue appropriate for DFS and BFS,
respectively? Why is BFS time O(V + E)?
13. How is topological sort performed? How can it be implemented via DFS?
Show that its running time is O(m + n), where m is the number of edges
and n is the number of vertices.
14. Illustrate the differences between Prim’s and Kruskal’s MST approaches
with an example.
8. NP-Completeness
1. Briefly discuss the relationship among P, NP, NP-complete, and NP-hard
problems.
2. What are parallel algorithms? Why did the concept of parallel algorithms
evolve? Write the parallel version of merge sort.
6. Can we solve any recursive problems using DP? If not, explain the con-
ditions for using DP. (Appears here again, but also under Dynamic Pro-
8
gramming.)
9. Miscellaneous Definitions
1. Define the following with necessary details:
• Poset
• Lattice
• Bipartite graph
• Sandwiching theorem
• Multigraph
• Complete graph
• Complete graph
• Bipartite graph
• Euler path
• Hamiltonian cycle
• Uniform hashing
• Double hashing
6. What are the invariants of a Red-Black tree? Prove that every red-black
tree with n nodes has height � 2 log(n+1).
9
10. Unclassified / Backtracking / Other
1. Find all possible solutions for the 4×4 chessboard and the 4-queens
problem. (Backtracking)
2. Identify the statement “Ternary search is much better than linear and
binary search.”
• Bipartite Graph
• Walk in a graph
10