Big O Notation Flashcards

2.3.1

1
Q

What is the point of Big-O Notation?

A

To find the upper bound of the function’s growth rate. Essentially the longest time it takes to turn the input into an output.

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

What is Big-O a measure of?

A

Time Complexity

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

What is Constant Complexity?

A

The algorithm always takes the same amount of time to execute, regardless of the size of the data.

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

What is the notation for constant complexity?

A

O(1)

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

What is an example of Constant Complexity?

A

Print Statements:
print(“hello world”)

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

What is Linear Complexity?

A

The time taken to execute an algorithm is directly proportional to the size of the data. So as the size of the data doubles, so does the time taken to execute.

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

What is the notation for Linear Complexity?

A

O(n)

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

What is an example of Linear Complexity?

A

For Loops:
for item in list:
print(item)

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

What is Polynomial Complexity?

A

The amount of time taken to complete an algorithm is directly proportional to the square of the size of the data set

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

What is the notation for Polynomial Complexity?

A

O(n^2)

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

What is an example of Polynomial Complexity?

A

Nested For Loops (within other For Loops):
for items in list:
for items in list:
print(items)

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

What is exponential complexity?

A

The amount of time taken to complete an algorithm will double with every additional element

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

What is the notation for Exponential Complexity?

A

O(2^n)

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

What is an example of an Exponential Complexity?

A

Recursive Functions:
def algo(items):
x = int(items)
if x <= 1:
return x
return algo(x-2) + algo(x-1)

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

What is Logarithmic Complexity?

A

The time taken to execute the algorithm is proportional to the logarithmic result (log) of the input size.

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

What is the notation for Logarithmic Complexities?

A

O(log n)

17
Q

What is an example of Logarithmic Complexities?

A

Binary Search or other Divide-and-Conquer algorithms. As the size of the data set gets halved each time there is only a small increase in the number of comparisons being made for each new element. For example, doubling the number of elements only adds one additional comparison to the binary search.