0% found this document useful (0 votes)
26 views14 pages

Algo Lecture 11 12 Design Categories 08052024 125702pm

The document discusses various algorithm design strategies including dynamic programming, greedy algorithms, and branch and bound algorithms. It provides examples of each strategy and compares memoization and tabulation approaches. Key algorithm design strategies covered are dynamic programming, greedy algorithms, branch and bound algorithms.

Uploaded by

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

Algo Lecture 11 12 Design Categories 08052024 125702pm

The document discusses various algorithm design strategies including dynamic programming, greedy algorithms, and branch and bound algorithms. It provides examples of each strategy and compares memoization and tabulation approaches. Key algorithm design strategies covered are dynamic programming, greedy algorithms, branch and bound algorithms.

Uploaded by

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

Design & Analysis of

Algorithm
Dr. Iram Noreen
Classification of Algorithms
• Searching algorithms
• Sorting algorithms
• Compression algorithms
• Encoding algorithms
• Pattern matching algorithms
• Parsing algorithms
Algorithm Design Strategies
• Brute Force algorithm: It simply tries all possibilities until a satisfactory
solution is found. Does not implies any shortcuts to improve performance.
• Divide & Conquer: frequently used in searching & sorting. Works by
dividing problem in similar sub problems.
• Iterative algorithm: repetition using loops
• Dynamic Programming: Solve complex problems by breaking down into
simpler subproblems. Focused on solving each subproblem only once and
storing the results to avoids redundant computations, leading to efficient
solutions.
• Greedy algorithm: Tries for an immediate available best solution.
Algorithm Design Strategies
• Back Tracking algorithm: They use recursion to exhaust all
possibilities or until they find a solution in a large search space.
• Randomized algorithms: They use a random number at least once
during the computation for decision making.
• Optimization algorithms: May have many feasible solution and it
finds the best solution out of all possible feasible solutions.
• Branch and Bound Algorithm: It is used in combinatorial optimization
problems to systematically search for the best solution.
1. Dynamic Programming
• Dynamic programming helps to efficiently solve problems that have
overlapping subproblems and optimal substructure properties.
• The idea behind dynamic programming is to break the problem into
smaller sub-problems and save the result for future use, thus
eliminating the need to compute the result repeatedly.
• They work using momoization technique to find the best solution.
Memoization
• The term “Memoization” comes from the Latin word “memorandum”
(to remember), which is commonly shortened to “memo” in American
English, and which means “to transform the results of a function into
something to remember.”.
• In computing, memoization or memoisation is an optimization
technique used primarily to speed up computer programs by
eliminating the repetitive computation of results and returning the
cached result when the same inputs occur again.
• Memoization is actually a specific type of caching.
• It consists of recursion and caching.
Should I use tabulation or memoization?

• For problems requiring all subproblems to be solved, tabulation typically


outperforms memoization by a constant factor. This is because the
tabulation has no overhead of recursion which reduces the time for
resolving the recursion call stack from the stack memory.

• Whenever a subproblem needs to be solved for the original problem to be


solved, memoization is preferable since a subproblem is solved lazily, i.e.
only the computations that are required are carried out.

• Tabulation is usually faster than memoization, because it is iterative and


solving subproblems requires no overhead of recursive calls.
Python code example of implementing memoization using a
dictionary
Greedy Algorithm
• Takes the best value irrespective of the future consequences or final
outcome.
• It hopes to find a global optimum by continuously choosing local
optimal value.
• It prioritizes immediate benefits over long-term consequences,
making decisions based on the current situation without considering
future implications.
• While this approach can be efficient and straightforward, it doesn’t
guarantee the best overall outcome for all problems.
Examples of Greedy Algorithm
• Dijkstra’s algorithm: Finds the shortest path between two nodes in a graph.
• Kruskal’s algorithm: Finds the minimum spanning tree for a weighted graph.
• Huffman coding: Creates an optimal prefix code for a set of symbols based on
their frequencies. Usually used for compression and encryption.
• Fractional knapsack problem: Determines the most valuable items to carry in a
knapsack with a limited weight capacity.
• Activity selection problem: Chooses the maximum number of non-overlapping
activities from a set of activities.
• Scheduling and Resource Allocation: The greedy algorithm can be used to
schedule jobs or allocate resources in an efficient manner.
• Coin Change Problem: The greedy algorithm can be used to make change for a
given amount with the minimum number of coins, by always choosing the coin
with the highest value that is less than the remaining amount to be changed.
Pros & Cons
• Advantages
• Simple, Intuitive & easy
• Fast execution time
• Disadvantages
• Not always optimal
• Sensitive to input order
• Limited applicability
Branch and Bound Algorithms
• It works by dividing the problem into smaller subproblems, or
branches, and then eliminating certain branches based on bounds on
the optimal solution. This process continues until the best solution is
found or all branches have been explored.
• Branch and Bound is commonly used in problems like the traveling
salesman and job scheduling.

You might also like