BigO Flashcards

1
Q

What are the four most common functions used on data structures. These are also the four criteria used by BigO notation to score efficiency.

A
  1. Accessing elements
  2. Searching for an element
  3. Inserting an element.
  4. Deleting an element.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

BigO allows us to create a ‘report card’ based on the four criteria. This allows us to know what a certain data structure is…

A

Good at,
Bad at, and
When it should be used

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

What is the equation is used by BigO to calculate a functionality’s score in each of the four areas?

A

The Time Complexity equation.

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

How does a Time Complexity equation work?

A

By inserting the size of the data-set as an integer (n), and retuning the number of operations that need to be conducted by the computer before the function can finish.

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

What is the N value in BigO?

A

N is the size of the data set. (The amount of elements contained within the data structure)

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

When judging data structures, which scenario do we always use…

A

The worst case scenario. I.e. The longest time it could possibly take. E.g. The item we are searching for in an array is in the last possible location we attempt to check.

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

Why is it called BigO notation?

A

Because the function is represented by a big ‘O’ followed by a set of parentheses. E.g. O()

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

How do we pronounce the following…
O(2),
O(5)

A

O of 2
O of 5
O being pronounced “oh” like the letter, and NOT zero.

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

What does O(7) mean?

A

It takes 7 operations of the computer before our function can finish.

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

O(4) is an example of Constant Time. What does constant time mean?

A

No matter the size of our data set, it will always take the same amount of time to run. These arent very common though, as most of the time, our integer (n), is going to have some adverse effect on how many operations it takes.

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

Why does BigO measure efficiency in terms of number of operations and not time?

A

Because measuring by time is biased towards better hardware. Number of operations levels the playing field.

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

BigO isn’t the only input you should consider when deciding which data structure to implement in your program … Why?

A

Many data structures have specific quirks or features which separate them from the rest and may provide additional functionality that make them extremely useful.

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

What are the 7 most common Time Complexity equations, from most efficient to least efficient? Also which are considered Good and which bad?

A
O(1) GOOD, 
O(log n) GOOD,
O(n) GOOD,
O(n log n) BAD,
O(n^2), n to the power of 2, BAD, 
O(2^n) 2 to the power of n, BAD
O(n!), n Factorial, VERY BAD
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the absolute best “score” a data structure can achieve?

A

O(1)

This means no matter what the size of the data set is, the task will be completed in a single instruction.

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

When is O(log n) most efficient?

A

When the data set size increases. Its efficiency slope decreases when n increases.
Think BinarySearch, for an n of 10 the first operation cuts it by half ruling out 5 elements, whereas for an n of 1,000,000 the first operation cuts it by half ruling out 500,000 elements!

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

Give an example of an O(1) operation.

A

Array access with index.

17
Q

Give an example of an O(log n) operation.

A

A BinarySearch on a sorted list.

18
Q

Give an example of an O(n) operation.

A

Array linear search when data is unsorted. Array inserts and deletes.

19
Q

Name the 3 “GOOD” equations.

A
  1. O(1)
  2. O(log n)
  3. O(n)
20
Q

Name the 3 “BAD” equations.

A
  1. O(n log n)
  2. O(n^2)
  3. O(2^n)
21
Q

How does O(n log n) perform as the data-set size (n) increases?

A

I becomes more INEFFICIENT as n increases. Its efficiency slope increases when n increases.

22
Q

Which two equations are exponential?

A
  1. O(n^2)

2. (2^n)

23
Q

Why are exponential equations very bad?

A

The larger the data-set you have, the more inefficient they become.