Big O Flashcards

1
Q

Best, worst, expected cases

A

Describe the big O (or big theta) time for particular inputs or scenarios

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

Big O, big omega, big theta

A

Describe the upper, lower, and tight bounds for the runtime

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

Add runtimes

A

If the algorithm is “do this, then do that”

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

Multiply runtimes

A

If the algorithm is “do this for each time you do that”

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

Amortized Time

A

Concept that takes into account the worst case happens every once in a while, but once it does it won’t happen again for so long that the cost is “amortized”

The motivation for amortized analysis is that looking at the worst-case run time per operation, rather than per algorithm, can be too pessimistic.

Example: If the insertion time takes O(2x), the amortized time for each insertion is O(1)

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

.sort( )

A

Modifies the list it is called on in-place, runtime of O(n log n)

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

sorted( )

A

Creates a new copy of the modified list in memory, does not modify the original list, primary difference is additional space complexity vs .sort( )

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

Try/Except

A

A try statement may have more than one except clause, to specify handlers for different exceptions

Example:
while True:
… try:
… x = int(input(“Please enter a number: “))
… break
… except ValueError:
… print(“Oops! That was no valid number. Try again…”)
… except:
… print(“Don’t try this at home”)

Be wary of a last except: with nothing specified like above - the last except clause may omit the exception name(s), to serve as a wildcard. Use this with extreme caution, since it is easy to mask a real programming error in this way

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

Big O

A

Measures how time scales with respect to some input variables

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

O(1)

A

Constant time

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

O(n)

A

Linear time

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

O(n^2)

A

Quadratic time

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