Complexity Flashcards

1
Q

What is the master method?

A

A method for finding the TIME COMPLEXITY of a RECURSIVE algorithm (Θ)

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

What form are the recurrences that we can solve with the master method?

A

T(N) = aT(n/b) + f(n)
a>=1 subproblems
b> 1 subsets of input
f(n)>0

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

What are the three cases in the master method?

A

1.f(n) = O (n^(logb(a)- e)), e>0
T(n) = Θ(n^(logb(a)))

2.f(n) = Θ(n^logb(a))
T(n) = Θ(n^(logb(a)) * logn)

3.f(n)= Ω(n^(logb(a)+e))
af(n/b) <= cf(n), c < 1
T(n ) = Θ(f(n))

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

What is the intuition behind the master method?

A
<= is O
== is Θ
>= is Ω
-Compare f(n) to n^(logb(a))
largest is the solution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the worst case complexity of binary search? Why?

A

logn

It is the number of times you have to cut array in half to make it a single element.

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

Give a simple definition of Asymptotic Analysis.

A

Asymptotic: BEHAVIOUR of function when input gets LARGE. Analysis tries to PREDICT this.

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

Is O(f+g)εO(f)+O(g) true or false?

A

False
O(n^2+n) =n^2
O(n^2) + O(n) = n^2 + n
There’s no constant to make the first less than the second

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Is O(fxg) = O(f)x O(g)
True or False?
A

True
O(n^2 x n) = n^3
O(n^2)x O(n) = n^3

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

What does it mean for f to be Θ(g)?

A

There’s two constants c1,c2>0 and a No>=N s.t

f is always between c1g and c2g

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

Explain the worst time complexity of mergesort

A

nlogn. It takes logn splits to SPLIT array into n elements. Then it has to ACCESS each element, which take n time.

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

What do recurrences express?

A

The running TIME of RECURSIVE algorithms

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

What are the 3 methods we learned to solve recurrences?

A
  1. Master Theorem
  2. Substitution
  3. Iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly