Design and Analysis of Algorithms
Why We Study Algorithms
"Every program you write solves a problem. But how efficiently you solve it — that’s where
algorithms come in. DAA helps us choose the best way to solve problems in terms of time
and space."
examples:
Searching a contact in your phone (Linear vs Binary Search)
Sorting files by name or date (Bubble Sort vs Merge Sort)
Navigation apps (Dijkstra's Algorithm)
In Design and Analysis of Algorithms (DAA) , algorithms are broadly classified based on
their approach or technique used to solve problems.
main types of algorithms:
1. Brute Force Algorithm
Idea: Try all possible solutions and pick the best one.
Example: Linear Search, Bubble Sort
Use: Simple, but not efficient for large inputs.
2. Divide and Conquer
Idea: Divide the problem into sub-problems, solve them independently, and combine the
results.
Example: Merge Sort, Quick Sort, Binary Search
Efficiency: Often improves performance using recursion.
3. Greedy Algorithm
Idea: Take the best option at each step without thinking about the future.
Example: Kruskal’s and Prim’s Algorithms, Huffman Coding
Use: Works well for optimization problems.
4. Dynamic Programming (DP)
Idea: Solve complex problems by breaking them into overlapping subproblems and
storing results.
Example: Fibonacci series (DP version), Knapsack problem
Use: Saves time using memoization or tabulation .
5. Backtracking
Idea: Try a solution, and if it doesn’t work, go back and try a different one.
Example: N-Queens Problem, Sudoku Solver
Use: Solves constraint-based problems.