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

DAA Exam Notes

The document provides exam notes on various algorithms, including Binary Search, Merge Sort, Quick Sort, and others, outlining their problems, algorithms, time complexities, and applications. It covers both classic algorithms like Dijkstra's and Floyd-Warshall for shortest paths, as well as optimization problems like the Knapsack and Traveling Salesperson Problem. Additionally, it discusses NP problems and their classifications.

Uploaded by

darshanawale02
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 views6 pages

DAA Exam Notes

The document provides exam notes on various algorithms, including Binary Search, Merge Sort, Quick Sort, and others, outlining their problems, algorithms, time complexities, and applications. It covers both classic algorithms like Dijkstra's and Floyd-Warshall for shortest paths, as well as optimization problems like the Knapsack and Traveling Salesperson Problem. Additionally, it discusses NP problems and their classifications.

Uploaded by

darshanawale02
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/ 6

Design and Analysis of Algorithms (DAA) Exam Notes (6-Mark Format)

1. Binary Search
Problem: Find an element in a sorted array using divide and conquer.

Algorithm:
1. Set low = 0, high = n - 1.
2. 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
3. If not found, return -1.

Time Complexity: O(log n)


Application: Efficient search in sorted data.

2. Merge Sort
Problem: Sort an array using divide and conquer.

Algorithm:
1. Divide the array into halves.
2. Recursively sort each half.
3. Merge the sorted halves.

Time Complexity: O(n log n)


Application: Stable sorting algorithm used in external sorting.

3. Quick Sort
Problem: Sort an array using partitioning.

Algorithm:
1. Pick a pivot.
2. Partition array into two: elements < pivot and > pivot.
3. Recursively apply to sub-arrays.

Time Complexity:
- Best/Average: O(n log n)
- Worst: O(n^2)
Application: Efficient in-memory sorting.

4. Hamiltonian Cycle
Problem: Find a cycle that visits every vertex exactly once.

Approach: Backtracking

Steps:
1. Start from any vertex.
2. Recur for all adjacent vertices.
3. Check if all vertices are visited and return to start.

Time Complexity: O(n!)


Application: Routing, puzzle games.

5. Minimum Spanning Tree


Prims Algorithm:
- Start from any node.
- Pick the minimum weight edge connecting visited & unvisited node.
- Repeat until all nodes are included.

Time: O(V^2) or O(E log V) using heap.

Kruskals Algorithm:
- Sort edges by weight.
- Add edge if it doesnt form a cycle (using Union-Find).

Time: O(E log E)


Application: Network design.

6. Dijkstras Algorithm
Problem: Find the shortest path from source to all nodes in weighted graph.

Steps:
1. Initialize distance to all nodes as , source as 0.
2. Use min-priority queue to pick minimum dist node.
3. Relax all adjacent edges.
Time Complexity: O(V^2) or O((V+E) log V) with heap.

7. Bellman-Ford
Problem: Find shortest paths with possible negative weights.

Steps:
1. Initialize distances to , source = 0.
2. Repeat V-1 times: relax all edges.
3. Check for negative cycles.

Time: O(VE)

8. Floyd-Warshall
Problem: Find shortest paths between all pairs.

Steps:
1. Use a 2D matrix dist[i][j].
2. Update dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

Time: O(V^3)

9. Strassens Matrix Multiplication


Problem: Multiply matrices faster than O(n^3).

Steps:
1. Divide matrices into 4 submatrices.
2. Use 7 multiplications instead of 8.

Time: O(n^2.81)

10. N-Queens Problem


Problem: Place N queens on an NN board so that no two queens attack each other.

Approach: Backtracking

Steps:
1. Place queen in row.
2. Check column & diagonals.
3. Backtrack if conflict.
Time: O(N!)

11. Sum of Subsets


Problem: Find subsets that sum to a given value.

Approach: Backtracking

Steps:
1. Include/exclude elements.
2. Track sum and prune branches.

Time: O(2^n)

12. Graph Coloring


Problem: Color graph such that adjacent nodes have different colors.

Approach: Backtracking

Time: O(m^n) where m = colors, n = vertices

13. Travelling Salesperson (TSP - B&B)


Problem: Find shortest route visiting all cities exactly once.

Approach: Branch and Bound

Time: O(n!)

14. 15-Puzzle Problem


Problem: Reach goal state from initial 4x4 board.

Approach: A* or Branch & Bound

Time: O(N^2)

15. Huffman Coding


Problem: Compress data using variable-length codes.

Steps:
1. Create min heap of frequencies.
2. Build tree and assign 0/1.

Time: O(n log n)

16. Knapsack Problem


Problem: Maximize value within weight limit.

0/1 Knapsack (DP): O(nW)


Fractional (Greedy): O(n log n)

17. Activity Selection


Problem: Select max number of non-overlapping activities.

Approach: Greedy

Steps:
1. Sort by finish time.
2. Select next activity that starts after previous ends.

Time: O(n log n)

18. Job Sequencing


Problem: Maximize profit by scheduling jobs with deadlines.

Approach: Greedy

Steps:
1. Sort by profit.
2. Schedule latest available slot before deadline.

Time: O(n log n)

19. Longest Common Subsequence (LCS)


Problem: Find longest sequence present in both strings.

Approach: Dynamic Programming

Time: O(mn)
20. NP Problems
P: Solvable in polynomial time.
NP: Verifiable in polynomial time.
NP-Complete: Both NP and as hard as any NP problem.
NP-Hard: As hard as NP-Complete, but not necessarily in NP.

Example: TSP is NP-Complete.

End of Notes

You might also like