Algorithm Complexity Flashcards

1
Q

What is an algorithm?

A

A clear list of steps to solve a problem. It must work well, be easy to follow, and end after a few steps.”

✅ Examples: recipe, sorting numbers
❌ Not examples: recognizing a face, judging beauty

Examples: Recipe for soup ✅, Sorting numbers ✅, Recognizing a face ❌, Ordering by beauty ❌.

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

What is algorithm efficiency?

A

How well an algorithm uses things like time, memory, or power

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

What is time complexity?

A

Shows how the number of steps grows as the input size (n) gets bigger, usually looking at the worst case

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

What is empirical analysis?

A

Running the algorithm with different input sizes and timing how long it takes

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

What is Big-O notation?

A

Big O tells how fast an algorithm slows down as the input gets bigger:
✅ It drops constants and lower terms
📈 It tells how fast the algorithm grows with big inputs

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

What is the Big-O classification for T(n)=n?

A

O(n)

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

What is the Big-O classification for T(n)=n+2?

A

O(n)

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

What is the Big-O classification for T(n)=2n²?

A

O(n²)

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

What is the Big-O classification for T(n)=1000?

A

O(1)

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

What is the Big-O classification for T(n)=n²+n+1?

A

O(n²)

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

What are common Big-O classes?

A
  • O(1) – Constant time
  • O(log n) – Logarithmic
  • O(n) – Linear
  • O(n log n) – Log-linear
  • O(n²) – Quadratic
  • O(n³) – Cubic
  • O(2ⁿ) – Exponential (intractable)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the time complexity of a Linear Search?

A

T(n) = n → O(n)

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

What is the time complexity of a Binary Search?

A

T(n) = log₂(n) → O(log n)

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

What is the time complexity for Matrix-Vector Multiplication?

A

Requires 2n² operations → O(n²)

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

How do functions f(n)=n² and g(n)=n²−3n+2 behave for large n?

A

As inputs get large, the smaller terms don’t matter, so we focus only on the biggest one

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

How to compute total complexity in sequential phases?

A

When combining parts, keep the one that grows the fastest. For example, O(n) + O(n²) becomes O(n²)

17
Q

How to compute total complexity in nested calls/compositions?

A

When steps happen inside each other (like loops inside loops), multiply their complexities. For example, O(n) × O(log n) = O(n log n)

18
Q

What are some Big-O tips?

A

Count loops (and nested loops)

Drop constants (e.g. 5n → n)

Focus on how it grows with big inputs

Use worst-case time

19
Q

What is the likely Big-O for code with one nested loop?

20
Q

What is the likely Big-O for code with triple nested loops?

21
Q

What is the likely Big-O for a single loop doing log-based halving?

22
Q

What are lessons from complexity regarding efficient algorithms?

A

Fast algorithms save time for big inputs. Some problems are just slow no matter what (like exponential ones)

23
Q

What can make a hard problem tractable?

A

Sometimes we change the problem or accept close-enough answers to make it faster to solve