Big O Flashcards

1
Q

Big O notation focuses on…

A

developing scalable code

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

What is Big O notation?

A

it is the upper bound, or worst case, measurement that defines how quickly or slow an algorithm’s runtime increases as inputs increase.

Big O notation is used as a measurement to inform us how efficient our algorithm is and how well it will scale.

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

How to measure Big O of an algorithm?

A

count the operations, then count the number of input elements. Then count the total amount of operations.

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

What is the overview of Big O ratings?

A

Constant time: excellent

linear time: fair

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

How can we simplify Big O notation?

A

With these 4 rules:

  1. Worse Case
  2. Remove Constants
  3. Different terms for inputs
  4. Drop Non Dominants
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Rule #1: Worst Case

A

When calculating Big O we always think in terms of the Worst Case.

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

Rule #2: Remove Constants

A

Big O is more of a big picture analysis. Will the scale well or will it scale poorly?

We do not need to know the intricate, decimal point calculation… yet..

So, we remove the constants.

example: O(2n) becomes O(n)

O(3 + n) becomes O(n)

O(7) becomes O(1)

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

Rule #3: Different terms for different inputs

A

if there are more than one input into the function/algorithm, then the Big O of that algorithm should be expressed in reference to those terms.

example:

def call_friends_and_family(family_group, friend_group):
    loop over family_group, then call each person by one
loop over friend_group, then call each person one by one

The Big O of this program would be expressed as: O(a + b), rather than O(n)

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

Rule #4: Drop Non Dominants

A

We focus on the most impactful items.

Example: O(n + n^2) would become O(n)

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

What causes additional time in a function? aka what takes up processing time?

A

Operations
Comparisons
Looping
Outside function calls

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

Why this matters?

A

The two principles of good programs are: 1) readability 2) scalability

When we develop a program we need to be thinking in terms of readability and scalability!

the right Data Structures + the right Algorithms = Good Programs

Data Structures are how we store information/data

Algorithms are how we interact with the data structures to create desired functionality to achieve desired output

Be obsessed with picking the right data structure and designing the right algorithm and your program will be good quality by default!

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

What are the 3 pillars of programming?

A
  1. Readability
  2. Memory aka Space Complexity
  3. Speed aka Time Complexity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Space Complexity: two ways to remember things

A

the Heap: where we store variables that was assign values to

the Stack: keep track of our function calls

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

What is Space Complexity?

A

Space complexity measures how much memory is being used relative to input. Space complexity focuses on ADDITIONAL SPACE needed as a result of the function.

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

What causes space complexity/takes up memory?

A
variables
data structures
function calls
allocations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

There’s a tradeoff between saving time and saving space. How do you decide which to optimize for?

A