Big O complexity Flashcards

1
Q

What are the different levels of BigO complexity?

A

O(log n)
O(n)
O(n log n)
O(n2)
O(n3)
O(2^n)

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

What are the two approaches to time complexity?

A

Theoretical Analysis - study the number of times the algorithm performs some basic operations

Empirical Analysis - Code and run the algorithm on a computer for some inputs and measure how long it takes

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

How is time complexity calculated

A

Number of basic operations in terms of the input size.

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

Downsides of Empirical analysis

A

▶ Depends upon the speed of the computer
▶ A slow algorithm will waste time to test
▶ It is hard to reason about how the algorithm will perform for an arbitrary input (we can’t try all inputs!)

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

What is Worst Case efficiency?

A

T(n) is the maximum running time (in
terms of number of basic operations) for any input of size n.

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

Rank in terms of efficiency:
Exponential
Constant
Logarithmic
Polynomial

A
  1. Constant O(1)
  2. Logarithmic O(log n)
  3. Polynomial O(n, n2, n3)
  4. Exponential O(2^n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

State the formal definition of big-O notation, i.e.:
f (n) ∈ O(g(n)) if

A

There exists constants c > 0
and n0 > 0
such that f (n) ≤ c · g(n)
for all n > n0

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