Algorithm_Questions_Brief_Answers
Algorithm_Questions_Brief_Answers
Asymptotic analysis evaluates algorithm efficiency as input size grows. Big O: worst-case; Omega
P: Problems solvable in polynomial time. NP: Verifiable in polynomial time. NP-Hard: At least as
Q3) What is Knuth Morris Pratt Method of pattern matching? Give examples.
KMP is a pattern matching algorithm using partial match table to avoid redundant checks. Example:
Backtracking tries placing queens one by one, backtracks if conflicts arise. Solves N-Queens by
Naive algorithm checks pattern at each position in text. Example: Searching 'ABC' in 'AABCABC'
Binary search finds target in sorted array by repeatedly dividing search interval in half.
Best: Minimum operations (ideal). Average: Expected operations. Worst: Maximum operations
Greedy algorithm makes the locally optimal choice at each step, aiming for global optimum.
Quick sort partitions array around pivot, recursively sorts partitions. Example: [3,6,1] pivot=3 [1],
[6].
Multistage graph has stages and directed edges only to next stages. Used in shortest path
problems.
Greedy algorithm builds up solution piece by piece choosing most promising option at each step.
2. While feasible:
b. Add to solution.
3. Return solution.
Choose items with max value under weight limit. DP stores max value for each weight limit and item
combination.
Q14) Write an algorithm to find the minimum and maximum value using divide and conquer and also
Recursion is when a function calls itself. Solve recurrences using substitution, recursion tree, or
master theorem.
Schedule jobs to maximize profit before deadlines. Example: Jobs with deadlines and profits are
Branch and bound solves by exploring states using heuristics and pruning unpromising branches to
ii) Divide & conquer splits problems independently; DP solves overlapping subproblems.