📘 PAPER 4 – DESIGN & ANALYSIS OF ALGORITHMS (UNIT 3 – DIVIDE & CONQUER AND GREEDY METHODS) university of allahabad
🔴 UNIT 3 – DIVIDE & CONQUER AND GREEDY METHODS
🔹 PART A: DIVIDE AND CONQUER
1️⃣ Divide and Conquer Technique
✅ Definition
Divide and Conquer is an algorithm design technique that:
-
Divides the problem into smaller subproblems
-
Conquers them recursively
-
Combines the solutions
General Form:
Examples:
✔ Merge Sort
✔ Quick Sort
✔ Binary Search
✔ Matrix Multiplication
2️⃣ Matrix Multiplication
🔹 Normal Method
Time Complexity:
🔹 Strassen’s Matrix Multiplication
Reduces multiplication operations.
Time Complexity:
Advantage:
✔ Faster than normal method
✔ Used in large matrix computation
3️⃣ Convex Hull
✅ Definition
Convex Hull is the smallest convex polygon that encloses all points.
Algorithms:
-
Jarvis March
Applications:
-
Pattern recognition
-
GIS systems
🔹 PART B: GREEDY METHOD
4️⃣ Greedy Algorithm
✅ Definition
Greedy algorithm chooses the best option at each step hoping to get the global optimum.
Characteristics:
✔ Simple
✔ Fast
❌ May not give optimal solution always
5️⃣ Fractional Knapsack Problem
Problem:
Maximize profit with weight constraint.
Solution:
-
Take full item if possible
-
Take fraction if needed
Time Complexity:
✔ Greedy works here
❌ Not applicable for 0/1 knapsack
6️⃣ Minimum Spanning Tree (MST)
Definition:
A spanning tree with minimum total edge weight.
🔹 1. Prim’s Algorithm
Steps:
-
Start with any vertex
-
Select minimum weight edge
-
Add to tree
-
Repeat
Time Complexity:
🔹 2. Kruskal’s Algorithm
Steps:
-
Sort edges by weight
-
Add smallest edge
-
Avoid cycle
Uses:
✔ Union-Find
✔ Greedy technique
Difference: Prim vs Kruskal
| Prim | Kruskal |
|---|---|
| Vertex-based | Edge-based |
| Uses priority queue | Uses sorting |
| Dense graphs | Sparse graphs |
7️⃣ Single Source Shortest Path
🔹 Dijkstra’s Algorithm
Purpose:
Find shortest path from source to all vertices.
Condition:
✔ No negative edges
Time Complexity:
🔹 Bellman-Ford Algorithm
Advantage:
✔ Handles negative weights
Disadvantage:
❌ Slower than Dijkstra
Time Complexity:
📌 EXAM IMPORTANT QUESTIONS (UNIT 3)
✔ Explain Divide and Conquer
✔ Explain Strassen’s matrix multiplication
✔ Explain Greedy method
✔ Difference between Prim and Kruskal
✔ Explain Dijkstra algorithm
✔ Explain Fractional Knapsack
Comments
Post a Comment