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

Merge Sort,Quick Sort

The document provides an overview of algorithms, including definitions of algorithms and program control, as well as various algorithmic approaches such as Divide and Conquer, Dynamic Programming, and Greedy Algorithms. It outlines specific examples for each approach, including Merge-Sort, Quick-Sort, and Dijkstra’s algorithm. The document emphasizes the structure and methodology behind these algorithms for problem-solving in computer programming.

Uploaded by

mahfujapple95
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 views4 pages

Merge Sort,Quick Sort

The document provides an overview of algorithms, including definitions of algorithms and program control, as well as various algorithmic approaches such as Divide and Conquer, Dynamic Programming, and Greedy Algorithms. It outlines specific examples for each approach, including Merge-Sort, Quick-Sort, and Dijkstra’s algorithm. The document emphasizes the structure and methodology behind these algorithms for problem-solving in computer programming.

Uploaded by

mahfujapple95
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/ 4

Weekly Note -Algorithm-2201

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.

2) What is Program Control?


Specifying the order in which statements are to be executed in a computer program
is called program control.

3) Write down Divide and Conquer algorithms approach?


Based on dividing problem into sub problems -
1. Divide problem into smaller sub problems.
 Sub problems must be of same type
 Sub problems do not need to overlap
2. Solve each sub problem recursively.
3. Combine solutions to solve original problem.
 Usually contains two or more recursive calls.

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):

Recall definition of Fibonacci numbers:


• F (n) = F (n-1) + F(n-2)
• F (0) = 0
• F (1) =1

0 1 1 ….. f(n-2) f(n-1) f(n)

anbM-25
b. Find shortest way by forward approach- Dynamic Programming-

d(S, T) = min{1+d(A, T), 2+d(B, T), 5+d(C, T)}


d(A,T) = min{4+d(D,T), 11+d(E,T)} = min{4+18, 11+13} = 22

d(B, T) = min{9+d(D, T), 5+d(E, T), 16+d(F, T)}


= min {9+18, 5+13, 16+2} = 18

d (C, T) = min{ 2+d(F, T) } = 2+2 = 4


d (S, T) = min{1+d(A, T), 2+d(B, T), 5+d(C, T)} = min{1+22, 2+18, 5+4} = 9.
The above way of reasoning is called backward reasoning

5) Write down the Greedy Algorithm approach?


Based on trying best current (local) choice:
 At each step of algorithm choose best local solution
 Hope local optimum lead to global optimum.
Greedy Algorithm – Example:
• Dijkstra’s Single Source Shortest Path
• Minimum Spanning Tree – Prim & Kruskal
• Fractional Knapsack Problem
• Huffman Coding

anbM-25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy