CS2004_Time_Complexity_Flashcards

(10 cards)

1
Q

What is Big-O notation?

A

Big-O notation describes the upper bound of an algorithm’s running time as the input size grows. It tells us the worst-case time complexity.

✅ Example: Binary Search runs in O(log n), meaning time increases logarithmically with input size.

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

What is Big-Theta (Θ) notation?

A

Big-Theta notation describes a tight bound on the running time of an algorithm. It indicates both the upper and lower bounds.

✅ Example: Merge Sort is Θ(n log n), meaning it always runs in that time regardless of input.

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

What is Big-Omega (Ω) notation?

A

Big-Omega notation gives the best-case lower bound on an algorithm’s runtime — the fastest it can possibly run.

✅ Example: Insertion Sort is Ω(n) when the list is already sorted.

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

What does T(n) represent?

A

T(n) represents the exact number of primitive operations performed by an algorithm on an input of size n.

✅ Example: A nested loop might perform T(n) = n^2 + 2n + 1 operations.

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

How do you simplify T(n) to Big-O?

A

Drop all lower-order terms and constants, and keep only the highest-order term.

✅ Example: T(n) = 2n^2 + 5n + 3 → O(n^2)

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

What is the time complexity of a loop from i = 1 to n?

A

O(n) — the loop runs n times, doing constant work each time.

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

What is the time complexity of nested loops (two loops from 1 to n)?

A

O(n^2) — inner loop runs n times for each of n iterations of the outer loop.

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

What does O(1) mean?

A

O(1) means constant time — the operation takes the same amount of time regardless of input size.

✅ Example: Accessing an element in an array by index.

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

Give examples of logarithmic time algorithms.

A

Binary Search, tree operations in balanced binary search trees.

✅ Example: Searching a sorted list with Binary Search → O(log n)

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

What is the difference between best, worst, and average case complexity?

A

Best: fastest time (optimistic), Worst: slowest time (pessimistic), Average: expected performance over all inputs.

✅ Example: Quick Sort has O(n log n) average, but O(n^2) worst case.

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