Big O Flashcards

1
Q

What is Big O and why is it important

A

Big O time is the language and metric we use to describe the efficiency of algorithms. no knowing this concept can severely hurt you when developing an algorithm

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

O(N)

A

asymptotic runtime increases linearly with the amount of work to be done

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

O(1)

A

Time taken to complete a task, no matter how large it gets is constant.

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

Academic definition of big O

A

Big O describes an upper bound on the time it takes to complete a task. Think of it as “ the algorithm is at least as fast as x run time”

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

Academic definition of Big Omega

A

Big Omega is like Big O but for a lower bound on runtime. can be thought of as “ the algorithm wont be faster than x runtime”

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

Academic definition of Big Theta

A

Big Theta is both big O and big Omega. ie an algorithm is Theta(N) if it is both O(N) and Omega(N). Theta gives a tight bound on runtime.

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

Best case

A

The case that the algorithm runs that gives the lowest/ fastest runtime.

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

worst case

A

a case in which the algorithm takes the maximum amount of time it can to solve a problem.

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

Expected case

A

the run time that an algorithm usually takes

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

Utility of the cases

A

Best case is rarely used. Usually, expected case and worse case are the same. if they are not, both need to be independently described

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

what is the relationship between best/worse/expected case and bigO/Theta/Omega?

A

Best/worse/expected cases describe the Big O time for particular inputs or scenarios
BigO/Omega /Thetadescribe the upper, lower and tight end bounds for runtime

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

Space Complexity

A

a measurement of the space required by an algorithm

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

Tips about space complexity

A

actually allocating space in memory effects complexity, but so do function calls where the function is placed on the stack. if the function is not placed on the stack, then it does not effect complexity

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

Drop the constants when using Big O

A

O(2N) becomes O(N),

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

Drop non-Dominant terms

A

always drop non dominant terms
O(N^2 + N ) becomes O(N^2)
O(N + logN) becomes O(N)

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

Multipart algorithms: add vs multiply

A

add runtimes when work is successive: example: two for loops (for loop a and b) execute one right after another. The total amount of work here is O(a+b)

17
Q

Multipart algorithms: add vs multiply

A

multiply run times when algorithm is of the form “ do this for each time you do that” ie a for loop inside a for loop

18
Q

Amortized run time makes no sense. Look it up

A

please

19
Q

Log N run times

A

occurs when the number of elements in the problem space gets halved each time. Think Binary search

20
Q

Recursive runtimes

A

Often, but not always, the run time will be O(branches ^depth)