Design, Analysis, Implementation Flashcards

1
Q

Big-O notation

A

Given two functions T(n) and f(n), that always return positive numbers,

T(n) ∈ O( f(n) )

if and only if there exist constants
c, n₀ > 0

such that,
for all n≥n₀,

T(n)≤cf(n)

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

5 Big-O Simplification Rules

A
  • Constant multiple rule
  • Domination rule
  • Addition rule
  • Multiplication rule
  • Transitivity rule
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Constant multiple rule

A

If T(n) ∈ O( f(n) )
and c>0,

then

T(n) ∈ O( c ∗ g(n) )

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

Domination rule

A

If T(n) ∈ O( f(n)+g(n) )
and
f(n) ∈ O( g(n) )

then

T(n) ∈ O( g(n) )

We say that g “dominates” f

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

Addition rule

A

If
T₁(n) ∈ O( f(n) )
and
T₂(n) ∈ O( g(n) )

then
T₁(n) + T₂(n) ∈ O( f(n) + g(n) ).

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

Multiplication rule

A

If
T₁(n) ∈ O( f(n) )
and
T₂(n)∈O( g(n) )

then
T₁(n) ∗ T₂(n) ∈ O( f(n)∗g(n) )

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

Transitivity Rule

A

If
T(n) ∈ O( f(n) )
and
f(n) ∈ O( g(n) )

then
T(n) ∈ O( g(n) )

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

Loop invariant

A

A property which is preserved at every iteration through the loop.

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

3 Steps to showing a loop invariant

A
  1. Initialization: The invariant is true at the beginning of the first iteration.
  2. Maintenance. If the invariant is true at the beginning of one iteration, it’s also true at the beginning of the next iteration.
  3. Termination. After the loop exists, the invariant PLUS the loop termination condition tells us something useful.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Big-Ω

A

T(n) ∈ Ω( f(n) )
if and only if
f(n) ∈ O( T(n) )

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

Big-Θ

A

T₁(n) ∈ Θ( T₂(n) )
if and only if both

T₁(n) ∈ O( T₂(n) ) and T₂(n) ∈ O( T₁(n) ).

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