Big O Flashcards

1
Q

What is Big O?

A

The language and metric we use to describe the efficiency of algorithms

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

What is best case runtime?

A

If all elements are equal, then quick sort will, on average, just traverse the array once. This is O(N).

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

What is worst case runtime?

A

Getting really unlucky and having to traverse the entire array many times…This is O(N^2).

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

What is expected case runtime?

A

If the worst case doesn’t happen over and over again…this is O(N log N).

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

What are the steps in determining runtime?

A
  1. Drop the Constants.
  2. Drop the non-dominant terms.
  3. Consider multi-part algorithms (add vs multiply).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which one is faster?

Min and Max1
1. int min = Integer.MIN_VALUE;
2. int max = Integer.MIN_VALUE;
3. for (int x : array) {
   if ( x < min ) min = x;
   if ( x > max) max = x;
}
A
Min and Max2
1. int min = Integer.MIN_VALUE;
2. int max = Integer.MIN_VALUE;
3. for (int x : array) {
   if ( x < min ) min = x;
}
4. for ( int x : array) {
     if ( x > max) max = x;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the hierarchy of dominant terms?

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

What is an example of O(log N) runtime?

A

Binary search algorithm…when you see a problem where the number of elements in the problem space gets halved each time.

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

Formally speaking, what is the formula for Big-O notation?

A

If F and G are functions, then F = O(G) if there exists some constant, C, such that |F(x)| <= C * |G(x)| for sufficiently large x.

In the equality case, when |F(x)| = C * |G(x)| for sufficiently large x, f = O(g).

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