Big O Notation Flashcards

(19 cards)

1
Q

What type of algorithm is O(1)?

A

An algorithm that takes a constant amount of time regardless of input data

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

What type of algorithm is O(n)?

A

An algorithm that takes linear time

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

What happens as input size increases in O(n)?

A

Number of instructions to be completed grows proportionally

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

What is an example of O(n) in coding?

A

For and while loops

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

What type of algorithm is O(n^2)?

A

Algorithm that takes a square time to complete

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

What is the performance of O(n^2) proportional too?

A

(data inputs)^2

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

What sorting algorithm uses O(n^2)?

A

Bubble sort

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

What’s an example of O(n^2) in coding?

A

Nested loops
e.g.

x = 12
for i = 1 to x
for j = 1 to
next j
next i

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

What would O(n^6) look like?

A

The power is the amount of loops

for a = 1 to n
for b = 1 to n
for c = 1 to n
for d = 1 to n
for e = 1 to n
for f = 1 to n
next f
next e
next d
next c
next b
next a

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

What type of algorithm is O(2^n)?

A

An algorithm that takes double the time to for each added data input

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

Why is O(2^n) not used as much?

A

It’s inefficient but some problems can only be solved in exponential time

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

What algorithms use O(2^n)?

A

Recursive function with two calls
Fibonacci sequence with recursion

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

What type of algorithm is O(logn)?

A

An algorithm that takes very little time as the size of the input grows larger.

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

What is the base log for O(logn)

A

Base 2 NOT 10

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

What sorting algorithm is an example of O(logn)?

A

Binary search

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

What are the O notations ranked from least efficient to most efficient?

A

O(2^n)
O(n^2)
O(n)
O(logn)
O(1)

17
Q

Whats the best time complexity for all the searching algorithms?

18
Q

Whats the worse time complexity for a linear search, binary search tree and hashing?

19
Q

Whats the worse time complexity for