Complexity Analysis Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Define the Θ-notation

A

For a given function g(n), we denote by Θ(g(n)) the set of functions

Θ(g(n)) = { f(n): there exist positive constants c1, c2 and n0 such that 0 ≤ c1 g(n) ≤ f(n) ≤ c2 g(n) for all n ≥ n0 }

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

What is the difference between the Θ, O and Ω notation?

A

The Θ notation asymptotically bounds a function from above and below.
The O notation is used when we have only an asymptotic upper bound.
The Ω notation is used when we have only an asymptotic lower bound.

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

Define the O-notation

A

For a given function g(n), we denote by O(g(n)) the set of functions

O(g(n)) = { f(n): there exist positive constants c and n0 such that 0 ≤ f(n) ≤ c g(n) for all n ≥ n0 }

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

What is the difference between amortized analysis and average-case analysis?

A

Amortized analysis differs from average-case analysis in that probability is not involved.
An amortized analysis guarantees the average performance of each operation in the worst case

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

Suppose we had an algorithm that took in an array of strings, sorted each string, and then sorted the full array. What would the runtime be?

A

We cannot just use a single variable like N here for the Big O - Notation, since we have two different values here, the number of elements in the array (‘a’) and the size of the largest string (‘s’).

Sorting each string takes O(s log s) time and we have to do it for each string, so the time for the string comparison is O(a*s log s).
Now we have to sort the whole array. Beware that this is not simply O(a log a), because we need to compare the strings. Each comparison takes O(s) time.

So the final runtime will be O(as log s + sa log a) = O(a*s (log a + log s))

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

What is the runtime of calculating a fibonacci numbers (without memoization)?

A

O ( 2^n)

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

What is the runtime of calculating a fibonacci numbers (with memoization)?

A

O (n)

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