Algo: Misc Flashcards

1
Q

Types of Algorithms

A
  1. Brute Force
  2. Greedy
  3. Divide and Conquer
  4. Dynamic Programming
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe Brute Force algorithm

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe Greedy algorithm

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe Divide & Conquer algorithm

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe Dynamic Programming algorithm

A

DP algorithms solve by combining results of sub-problems like Divide and Conquer. It depends on “remembering” the past.

Two patterns:

  1. Memoization
  2. Tabulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Memoization in DP

A

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,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Tabulation in DP

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly