0% found this document useful (0 votes)
3 views

Algorithm Design Techniques [Unit 2]

Uploaded by

Krish Rai
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)
3 views

Algorithm Design Techniques [Unit 2]

Uploaded by

Krish Rai
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/ 8

Algorithm Design

Techniques
This lesson explores essential techniques used in crafting effective
algorithms. We'll cover iterative techniques, divide and conquer,
dynamic programming, and greedy algorithms, delving into their
principles, strengths, and illustrative examples.
Iterative Techniques
Iterative Techniques Strengths

Iterative techniques involve repeating a set of Iterative techniques are often simple and
instructions until a condition is met. This approach is straightforward to implement. Their step-by-step
often used for tasks involving repetition and iteration. approach can be easily understood and debugged.

Examples:

• Looping through a list to find a specific element.


• Calculating the factorial of a number.
Divide and Conquer

Divide
1 Break down a large problem into smaller subproblems of the same type.

Conquer
2
Solve the subproblems recursively.

Combine
3 Merge the solutions of the subproblems into a solution
for the original problem.
Dynamic Programming
Overlapping Subproblems
1
Identify subproblems that are solved multiple times.

Optimal Substructure
2 The optimal solution to the problem can be constructed from optimal
solutions of its subproblems.

Memoization or Tabulation
3
Store and reuse solutions of previously solved subproblems.
Greedy Algorithms
Local Optimality
At each step, choose the best option available without
looking ahead.

Global Optimality
Hope that a series of locally optimal choices lead to a
globally optimal solution.

Not Always Guaranteed


Greedy algorithms may not always find the optimal
solution, but they are often efficient and provide a
good approximation.
Illustrations for Iterative
Techniques
Finding the Maximum
A simple iterative algorithm to find the largest element in a
list: loop through each element, compare it to the current
maximum, and update the maximum if necessary.

Calculating Factorial
An iterative algorithm for calculating the factorial of a number:
start with 1, multiply it by the number, then decrement the
number and repeat until reaching 1.
Illustrations for Divide and
Conquer
1 Merge Sort
Recursively divides a list into halves, sorts each half,
and merges the sorted halves.

2 Quick Sort
Picks an element as a pivot, partitions the list around
the pivot, and recursively sorts the partitions.
Illustrations for Dynamic
Programming and Greedy
Algorithms

Coin Change Shortest Path


Dynamic programming A greedy approach to finding
approach to find the minimum the shortest path in a graph,
number of coins needed to using Dijkstra's algorithm to
make a given amount, using iteratively select the edge with
memoization to store solutions the smallest weight.
for subproblems.

You might also like