Merge Sort,Quick Sort
Merge Sort,Quick Sort
1) What is Algorithm?
A procedure for solving a problem in terms of the actions to be executed, and the
order in which these actions are to be executed is called an algorithm.
a. Merge-Sort:
Array: 5 2 4 1 7 3 2 6
anbM-25
b. Quick-Sort:
c. Binary Search:
Let the element to search is, K = 56
anbM-25
4) Write down Dynamic Programming Algorithm approach?
Set up a recurrence relating a solution to a larger instance to solutions of some
smaller instances.
Solve smaller instances once.
Record solutions in a table.
Extract solution to the initial instance from that table.
Dynamic Programming – Example:
• 0-1 Knapsack
• Longest Common Subsequence
• Longest Increasing Sequence
• Sum of Subset
• Warshall’s All pairs shortest path
• Bellman Ford’s Single Source Shortest Path
• Matrix Chain Multiplication
a. Fibonacci Algorithm :
Recall definition of Fibonacci numbers:
• F (n) = F (n-1) + F (n-2)
• F (0) = 0
• F (1) = 1
Computing the nth Fibonacci number recursively (top-down):
anbM-25
b. Find shortest way by forward approach- Dynamic Programming-
anbM-25