Week 6 Flashcards

1
Q

What is dynamic programming?

A
  • A technique for solving optimisation problems
  • similar solution to divide and conquer except the recursive calls are replaced by reference to a table of values computed by subproblems of the original problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is a problem solved by dynamic programming?

A
  1. characterise the structure, key elements and parameters of the problem and how they related to each other
  2. define the value of the optimal solution recursively, express the optimal solution in terms of it’s subproblems
  3. define base cases (subproblems that can be solved directly/need no further decomposition)
  4. define a recurrence relation which tells us the relationship between subproblems
  5. Solve the subproblems and combine them to obtain the solution of the original problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What type of problem are dynamic programming solutions used to typically solve?

A

Optimisation problems
- that have a maximising or minimising function
- applied where brute force is infeasible

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

What are the 3 features a problem must have to be effectively solved by dynamic programming?

A
  1. must be able to break the problem into subproblems with a similar structure
  2. the optimal solutions must be composed of the optimal solutions of subproblems
  3. optimal solutions to some subproblems can contain subproblems in common (overlap)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is memoisation?

A
  • Where computed values are stored in cache and later retrieved when they’re needed instead of recomputing them, in order to make applications more efficient/faster
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What can make the run time of a dynamic programming solution poor?

A

Subproblems overlap and recompute the same value over and over which is inefficient

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

What is the naive dynamic programming runtime of calculating the fibonacci sequence?

A

O(2^n)

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

What is the dynamic programming memoisation run time of calculating the fibonacci sequence?

A
  • Removing recalculating values and taking them from a table give us O(n^2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What problems can we solve with dynamic programming?

A
  • Calculating Fibonacci sequence
  • {0,1} Knapsack Problem
  • Weighted Interval Scheduling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the dynamic programming runtime of the solution for the {0,1} Knapsack problem?

A

O(n*W)
- where n is the number of elements to be packed
- and W is the max weight the knapsack can hold
- inefficient as run time is exponential as Wmax is exponential?

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

What is weighted interval scheduling?

A
  • have a collection of tasks to schedule with a start and finish time but also a value Vi
  • aim is to schedule a subset of non-conflicting tasks have the maximum total value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the time complexity for finding the weighted interval scheduling problem solution using dynamic programming?

A

O(n*logn) since we use memoisation

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

What can we use to prove that the dynamic programming solution for the weighted interval scheduling problem is correct?

A

We can use proof by induction
- since every succeeding task’s optimal solution can be calculated by the optimal solutions of preceeding tasks (computed and stored in the dynamic programming table),
- we can show that the induction base holds and then show the induction step also holds

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