Javaalg
- T(n) = aT(n/b) + f(n)
- < -> n^(log_b(a))
- n^(log_b(a)) * log(n)^d -> n^(log_b(a)) * log(n)^(d+1)
- > -> f(n)
- Dynamic Programming Design
- State the problem as formally as possible.
- Identify sub-problems.
- Find and prove correct a self-reduction from the problem to one or more of its sub-problems.
- Identify overlapping sub-problems.
- Select an appropriate data structure to store the solutions to sub- problems (usually an array).
- Design an iterative algorithm that solves the sub-problems from easiest (smallest) to hardest (largest) using the self-reduction and stores their solutions in the data structure.
- Analyse the runtime of the algorithm.
- It is often easier to compute a minimum or maximum value first, and then recover the solution meeting that minimum or maximum.
- Greedy Algorithms
- A problem has the greedy choice property for a particular locally optimal choice if making the locally optimal choice leads to a globally optimal solution to the problem.
- Making a greedy choice is another means of reducing a problem to a subproblem.
- Unlike Dynamic Programming the greedy choices will not be reconsidered in a greedy algorithm.
- There is often more than one greedy choice we might make locally.
- Some of these choices will have the greedy choice property whereas others will not.
- Counterexample: To prove the greedy choice is incorrect we need only find an instance of the problem that it does not work on.
- Proof of Correctness: To prove the greedy choice correct we use a form of induction.
-
Often a greedy or dynamic programming approach solves the graph problem, but not always.
- MST and Prim’s Algorithm
- Prim
- Kruskal
- Dijkstra
Written on December 13, 2020