Dynamic programming Flashcards

1
Q

how is Dynamic programming similar to devide-counquer

A

both solve problems by combining the solutions to subproblems.

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

what type of proplems dose DP solve

A

solve optimization problems

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

why is dynamic programming important

A

It applies when the subproblems overlap ( subproblems are dependent).
.
divide-and-conquer algorithm does more work than necessary, repeatedly solving the common subsubproblems.
and this why DP exiest

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

A dynamic programming algorithm solves each subsubproblem…….

A

once and then saves its answer in a table (array), thereby avoiding the work of re-computing the answer every time it solves each subproblem

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

Dynamic-programming algorithm consists of a sequence of four steps:

A
  • Characterize the structure of an optimal solution.
  • Recursively define the value of an optimal solution.
  • Compute the value of an optimal solution, typically in a bottom-up fashion.
  • Construct an optimal solution from computed information
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

in what style fose DP solve proplems

A

bottom-up

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

how can DP solve fibbonaici

A

by saving information of f(0),f(2),f(4)and not compute them every time istade it just retrive it from an array

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

what big o of Fibonacci Series

A

O (2ˆn) “exponential time

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

time complexity of fibonacci series when solved in DP style

A

O(n)instade of O(2ˆn)

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

The two key ingredients that an optimization problem must have in order to apply dynamic programming

A

1-Optimal substructure
-A problem exhibits optimal substructure if an optimal solution to the problem contains within its
-optimal solutions to subproblems.
In dynamic programming, we build an optimal solution to the problem from optimal solutions to subproblems.
.
2-Overlapping subproblems
-The space of subproblems must be “small” in
-Dynamic-programming algorithms
-take advantage of overlapping subproblems by solving each subproblem once and then storing the solution

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

Some applications of dynamic programming :

A
  • Matrix-chain multiplication
  • Knapsack problem
  • Longest common subsequence problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

goal of knapsack proplem

A

to get the maximum total profit that we can carry is no more than some fixed number W.

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

talk about the Two versions of the knapsack problem

A

1Fractional knapsack problem
Items are divisible: you can take any fraction of an item.
Some instances can be solved with greedy algorithm.

0-1 knapsack problem
Items are indivisible: You either take an item or not.
Some instances can be solved with dynamic programming.

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

Number of items n=3
Maximum capacity W=50
how to choose most value item
andfind the result table

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

It is called a “fractional” problem because….

A

a fraction of each item can be taken.

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

big o of Knapsack Problem: brute-force approach
and how to minimise it

A

it has bit O(2ˆn)
mimise it with DP and have big o of O(N*W)

14
Q

how is 0-1 Knapsack Problem: brute-force approach done

A
15
Q

IF you found it important complete slide 27-31

A

OK

16
Q

write the algorthim of 0-1 knapsack

A
17
Q

what the input and output of knapsack algorthim

A
18
Q

solve

A
18
Q

in Constructing an optimal solutionTo select the items that make the max profit
there is two ways mention them

A
18
Q

whats the algorthim to find the optimal soultion from given table

A
18
Q

whats the running time to find the optimal soltion knapsack DP algorthim

A

The running time is: O( n * W )

19
Q

solve

A
20
Q

how to benfit from DP style

A

When the solution can be recursively described in terms of partial solutions, we can store these partial solutions and re-use them as necessary (memorization)

21
Q

Running time of dynamic programming algorithm (both methods) vs. naïve algorithm:

A

0-1 Knapsack problem: O(W*n) vs. O(2ˆn)