0% found this document useful (0 votes)
2 views3 pages

Algorithm Units Notes

The document outlines key algorithm design techniques including Divide and Conquer, Greedy Algorithms, Dynamic Programming, Backtracking and Branch & Bound, and NP-Complete problems. Each unit provides a summary, examples, and pseudocode for various algorithms. The focus is on solving complex problems through systematic approaches and optimization techniques.

Uploaded by

Kishan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Algorithm Units Notes

The document outlines key algorithm design techniques including Divide and Conquer, Greedy Algorithms, Dynamic Programming, Backtracking and Branch & Bound, and NP-Complete problems. Each unit provides a summary, examples, and pseudocode for various algorithms. The focus is on solving complex problems through systematic approaches and optimization techniques.

Uploaded by

Kishan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Short Notes on Analysis and Design of Algorithms

Unit I: Divide and Conquer

Summary: This method divides the problem into smaller subproblems, solves each recursively, and

combines the results.

Examples: Binary Search, Merge Sort, Quick Sort, Strassens Matrix Multiplication
Pseudocode:
BinarySearch(arr, key):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == key:
return mid
else if arr[mid] < key:
low = mid + 1
else:
high = mid - 1
return -1

Unit II: Greedy Algorithm

Summary: Greedy algorithms make the locally optimal choice at each step in hope of finding the

global optimum.

Examples: Huffman Coding, Kruskals and Prims MST, Job Scheduling, Fractional Knapsack
Pseudocode:
GreedyKnapsack(wt[], val[], W):
for i in 0 to n:
ratio[i] = val[i] / wt[i]
sort items by ratio
for item in sorted list:
if item can fit:
take full item
else:
take fraction

Unit III: Dynamic Programming


Summary: Solves problems by combining solutions to subproblems, storing intermediate results.

Examples: 0/1 Knapsack, Floyd-Warshall, Matrix Chain Multiplication, Longest Common

Subsequence
Pseudocode:
Knapsack(wt[], val[], W, n):
dp = array[n+1][W+1]
for i from 0 to n:
for w from 0 to W:
if i==0 or w==0:
dp[i][w] = 0
else if wt[i-1] <= w:
dp[i][w] = max(val[i-1] + dp[i-1][w - wt[i-1]], dp[i-1][w])
else:
dp[i][w] = dp[i-1][w]
return dp[n][W]

Unit IV: Backtracking and Branch & Bound

Summary: Backtracking solves problems incrementally and abandons solutions when not viable.

Branch & Bound improves by pruning paths.

Examples: 8 Queens Problem, Graph Coloring, Hamiltonian Cycle, Travelling Salesman Problem
Pseudocode:
SolveNQueens(board, row):
if row >= N:
print(board)
return
for col in 0 to N:
if isSafe(board, row, col):
board[row][col] = 1
SolveNQueens(board, row + 1)
board[row][col] = 0

Unit V: NP-Complete and Approximation Algorithms

Summary: Introduces problems that are hard (NP-Hard/NP-Complete), and approximation

techniques for practical solutions.

Examples: Subset Sum Problem, Vertex Cover, Travelling Salesman (approx), Data Stream
Algorithms
Pseudocode:
ApproxVertexCover(graph):
cover = set()
while E is not empty:
select (u, v) from E
add u and v to cover
remove all edges incident to u or v
return cover

You might also like