Ch4: Divide and Conquer Flashcards

1
Q

For the substitution method of solving recurrences, what technique can you try if you hit a snag in the math?

A

Revise the guess by subtracting a lower-order term (this will be <= what you try to prove, therefore T(n) <= new guess <= desired guess implies T(n) = O(desired))

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

3 steps of divide and conquer

A

DIVIDE the problem into subproblems that are smaller instances of the same problem, CONQUER the subproblems by solving them recursively (or trivially), COMBINE the subproblem solutions into the solution for the original problem

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

Case when subproblems are large enough to solve recursively

A

Recursive case

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

Case when subproblems are small enough to no longer recurse

A

Base case

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

Recurrence

A

An equation or inequality that describes a function in terms of its value on smaller inputs

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

3 methods of solving recurrences

A

Substitution method, recursion-tree method, master method

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

When we state and solve recurrences, we often omit…

A

floors, ceilings, and boundary conditions (assuming the latter are O(1))

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

Steps for the substitution method

A

1) Guess the form of the solution (we do this sometimes w/ output of recursion-tree method!) 2) Use mathematical induction to find the constants and show that the solution works

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

In a recursion tree, each node represents…

A

the cost of a single subproblem somewhere in the set of recursive function calls

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

Using the recursion tree method, we get the total T(n) by…

A

Summing the cost at each level, then summing all the level costs to get the total cost T(n)

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

A recursion tree is best used to…

A

generate a good guess which you can then verify using the substitution method

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

You can use a recursion tree as a direct proof of a solution to a recurrence if…

A

you are very careful when drawing out the recursion tree and summing the costs

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

How do you determine the recursion tree height (h) in terms of n?

A

Create an equation describing the subproblem size at a level i in terms of n: n[i] = f(n, i). Then solve the equation for the level i when the subproblem size = 1 (at the leaves of the tree). This is the tree height h

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

What is the key trick to solving an “unbalanced” recursion tree - one where the subproblems do not have equal sizes?

A

Determine which subproblem size leads you down the longest simple path from the root node to a leaf (the biggest subproblem). Since the tree is not complete, this longest tree height is an upper bound we can use, since we know the actual total cost will be smaller than that of a complete tree

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