Algorithm design
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 instructions until Iterative techniques are often simple and straightforward to
a condition is met. This approach is often used for tasks implement. Their step-by-step approach can be easily
involving repetition and iteration. understood and debugged.
Examples:
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.
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