Divide-and-conquer Flashcards

1
Q

What’s the recurrence relation and bigO time of the simple divide-and-conque for polynomial Multiplication

A

T(n) = 4T(n/2) + O(n)

T(n) = O(n2)

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

What’s the recurrence relation and bigO time of the Gauss’s trick for polynomial Multiplication

A

T(n) = 3T(n/2) + O(n)

T(n) = O(nlog23)

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

Master theorem. a/bd >1. What’s big O

A

O(nlogba)

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

Master theorem. a/bd <1. What’s big O

A

O(nd)

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

Master theorem. a/bd =1. What’s big O

A

O(ndlogn)

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

Binary search can only apply to sorted arrays?

A

Yes

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

What’s the recurrence of Binary search and what’s bigO time

A

T(n) = T(n/2)+O(1)

O(logn)

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

What’s the recurrence of Mergesort and what’s bigO time?

A

T(n) = 2T(n/2) + O(n)

O(nlogn)

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

Mergesort psedo-code

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

Is mergesort optimal?

A

Yes.

Consider any such tree that sorts an array of n elements. Each of its leaves is labeled by a permutation of {1, 2, … , n}. In fact, every permutation must appear as the label of a leaf. The reason is simple: if a particular permutation is missing, what happens if we feed the algorithm an input ordered according to this same permutation? And since there are n! permutations of n elements, it follows that the tree has at least n! leaves.

This is a binary tree, and we argued that it has at least n! leaves. Recall now that a binary tree of depth d has at most 2d leaves (proof: an easy induction on d). So, the depth of our tree–and the complexity of our algorithm–must be at least log(n!). And it is well known that log(n!)  >= c*n*log n for some c > 0.

We have established that any comparison tree that sorts n elements must make, in the worst case, (n log n) comparisons, and hence mergesort is optimal!

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

expected average and worst time of finding medium with good pivot?

A

T(n) <= T(3n/4) + O(n)

average time: O(n)

Worst time: O(n2)

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

expected average and worst time of quicksort

A

average time O(n logn)

worst time O(n2)

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

pseudo-code for finding good pivot and medium

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

BigO time for simpy matrix multiplication

A

O(n3)

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

what’s the Inversion formula of FFT coefficient matrix Mn(w)-1?

A

Mn(w)-1 = 1/n*Mn(w-1)

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

pseudo-code for The fast Fourier transform

A
17
Q

Why The columns of matrix Mn(w) are orthogonal to each other?

A
18
Q

running time for FFT?

A

T(n) = 2T(n/2) + O(n)

O(n log n)

19
Q

pseudo-code for merge function in mergesort

A