Week 2 Flashcards

1
Q

You work for a small medicine stocker. Your boss comes and asks your opinion on which of two approaches is faster for employees to search over an unordered set of medicines (strings).

Which of the following two approaches will tell your boss is faster? (Bonus marks for big o notations)

  • Sequential Search
  • Sort then Search
A

Neither, both are okay.

If repeated use, sort then search.

Sort Search: C(n) = O(n^2)
Sequential Search: C(n) = O(n)

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

What is a basic operation?

A

Operation that contribute most towards the total running time.

Typically the operation most frequently executed, although dependant on the time of each operation.

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

Identify the basic operation in the following pseudo code:

set s = 1
for i = 1 to n do
   s = s * a
end for
return s
A

Multiplication

Comparison

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

What is the basic running time estimation equation?

A

Running time approximately equal to time to execute a basic operation times number of basic operations:

t(n)≈Cop×C(n)

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

Define Worst Case, Best Case and Average Case

A

Worst: Maximum running time
Best: Minimum running time
Average: Average running time

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

For the following pseudo code, define the best, worst and average cases:

SequentialSearch(A[0...n-1], K)
set i = 0
while i < n and A[i] ≠ K do
   set i = i + 1
end while
return i
A
Best-Case = Cb(n) = 1
Worst-Case = Cw(n) = n

Where p = probability of key existing
Average-Case = Ca(n) = ((p(n+1))/2)+n(1-p)
∴ if p = 1, then Ca(n) = (n+1)/2
∴ if p = 0, then Ca(n) = n

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

What does Omega or Big-O notation stand for?

A

Order of Growth. (Upper bound)

Formally: t(n) (running time) ∈ O(g(n)) if g(n) is a function and c x g(n) is an upper bound on t(n).

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

Order the following bounds in terms of t(n), fastest to slowest.

O(n^2)
O(n)
O(1)
O(2^n)
O(n log n)
O(log n)
O(n!)
A
O(1)
O(log n)
O(n)
O(n log n)
O(n^2)
O(2^n)
O(n!)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Solve the equivalence function class for the following problem:

0.003n + n^3 -6

A

n^3

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