asymptotic complexity Flashcards

(18 cards)

1
Q

Why don’t we use a stopwatch to measure code performance?

A

Because it’s too imprecise due to human error and system noise.

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

Why is system time an unreliable metric for program complexity?

A

Because it’s affected by many external factors like OS activity and hardware.

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

What is the best way to analyze algorithm performance?

A

Count the number of operations as a function of input size.

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

What does T(n) = 3n² + 2n + 3 mean in complexity?

A

The algorithm performs roughly 3n² + 2n + 3 operations for input size n.

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

Which term dominates in 3n² + 2n + 3 as n grows?

A

n² — it determines the asymptotic growth.

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

What is Big-O notation used for?

A

Describing the upper bound of an algorithm’s growth rate (worst-case complexity).

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

What is the formal definition of Big-O?

A

f(n) = O(g(n)) if ∃ c > 0, n₀ such that f(n) ≤ c·g(n) for all n ≥ n₀.

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

What does Big-O ignore?

A

Constant factors and lower-order terms.

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

Is 3n² in O(n²)?

A

Yes — constants are ignored in Big-O.

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

Is n log n in O(n²)?

A

Yes — n log n grows slower than n².

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

Is 2ⁿ in O(n²)?

A

No — exponential growth outpaces polynomial growth.

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

What is the runtime of selection sort?

A

O(n²) — due to nested loops or repeated minimum searches.

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

What is Big-Ω notation?

A

A lower bound on algorithm growth — best case performance.

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

What is Big-Θ notation?

A

A tight bound — both upper and lower bounds match asymptotically.

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

What does T(n) = Θ(n²) mean?

A

The algorithm grows exactly like n² for large n.

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

What does it mean if an algorithm is O(1)?

A

It runs in constant time — performance does not depend on input size.

17
Q

What is a useful heuristic when comparing complexity classes?

A

Exponential > Polynomial > Logarithmic > Constant

18
Q

Why is Big-O more useful than raw timings?

A

Because it abstracts away machine-dependent behavior and focuses on scalability.