Algo: Misc Flashcards
Types of Algorithms
- Brute Force
- Greedy
- Divide and Conquer
- Dynamic Programming
Describe Brute Force algorithm
Generally the most straightforward and exhaustive option. Go over each and every possible solutions to the problem
Generally the first one that pops in the head to solve the problem.
Describe Greedy algorithm
Successful in very specific problem set like Huffman Encoding to compress data or to find shortest path through a graph.
This is done by making an optimal choice at each step in an attempt to find optimal solution to overall problem. Recursion is generally used.
In many cases where Greedy Algorithms fail, Dynamic Programming might be better choice
Describe Divide & Conquer algorithm
The problem is repeatedly divided into sub-problems until we reach a base case. At that point, we start solving the base cases and combining the answers from the base case to eventually provide answer for original problem.
Application: Sorting
Describe Dynamic Programming algorithm
DP algorithms solve by combining results of sub-problems like Divide and Conquer. It depends on “remembering” the past.
Two patterns:
- Memoization
- Tabulation
What is Memoization in DP
Memoization pattern is top-down pattern. Uses recursion.
Starts from a large problem and then breaks into small parts. And it looks for the solutions of a subproblem in a lookup table before computing solution,
What is Tabulation in DP
Tabulation is bottom-up pattern in DP. Avoids recursion.
Start from a small problem and populate the lookup table. Compute solution for original problem based on look up table.