🔴 UNIT 4 – DYNAMIC PROGRAMMING & BACKTRACKING
🟦 PART A: DYNAMIC PROGRAMMING
1️⃣ Dynamic Programming (DP)
✅ Definition
Dynamic Programming is a technique used to solve problems by:
✔ Breaking them into subproblems
✔ Solving each subproblem only once
✔ Storing results for future use
🔹 Properties of DP
-
Optimal Substructure
-
Overlapping Subproblems
2️⃣ 0/1 Knapsack Problem
Problem Statement:
Given:
-
Weight array
w[] -
Profit array
p[] -
Capacity
W
Goal:
Maximize profit without exceeding capacity.
DP Formula:
Time Complexity:
Difference: Fractional vs 0/1 Knapsack
| Feature | Fractional | 0/1 |
|---|---|---|
| Item division | Allowed | Not allowed |
| Approach | Greedy | Dynamic |
| Optimal | Yes | Yes |
3️⃣ Matrix Chain Multiplication
Purpose:
Find the most efficient way to multiply matrices.
DP Formula:
Time Complexity:
4️⃣ All-Pairs Shortest Path
🔹 Floyd–Warshall Algorithm
Used to find shortest paths between all pairs of vertices.
Formula:
Time Complexity:
5️⃣ Longest Common Subsequence (LCS)
Definition:
Find the longest sequence common to two strings.
Example:
DP Formula:
6️⃣ Traveling Salesman Problem (TSP)
Problem:
Find the shortest path visiting each city exactly once and returning to start.
Solution:
✔ Dynamic Programming
❌ NP-Hard Problem
🟦 PART B: BACKTRACKING & BRANCH AND BOUND
7️⃣ Backtracking
Definition:
Backtracking tries all possibilities and removes those which fail.
Applications:
-
N-Queen problem
-
Graph coloring
-
Subset sum
8️⃣ N-Queen Problem
Goal:
Place N queens on NxN chessboard so that:
-
No two queens attack each other
Approach:
✔ Place queen row by row
✔ Backtrack when conflict occurs
9️⃣ Graph Coloring
Objective:
Color graph vertices such that:
-
No adjacent vertices have same color
🔟 Sum of Subsets
Objective:
Find subsets whose sum equals target value.
1️⃣1️⃣ Branch and Bound
Definition:
Optimization technique that:
-
Uses bounds
-
Prunes unnecessary branches
Used In:
✔ Traveling Salesman
✔ Job Assignment
✔ Knapsack
📌 EXAM IMPORTANT QUESTIONS (UNIT 4)
✔ Explain Dynamic Programming
✔ Solve 0/1 Knapsack
✔ Explain Floyd Warshall
✔ LCS with example
✔ N-Queen problem
✔ Branch and Bound
No comments:
Post a Comment