LN7 Master Theorem, Counting Inversions, Fast Multiplication Flashcards

1
Q

What is the goal of the Counting Inversions problem?

A

The goal is to count the number of inversions in a sequence, where an inversion is defined as a pair of indices (i, j) such that i < j and a[i] > a[j].

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

What is the naive solution for Counting Inversions, and what is its time complexity?

A

The naive solution is to use a nested loop to count all inversions, which has a time complexity of O(n^2).

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

What is the main idea behind using divide-and-conquer for Counting Inversions?

A

The main idea is to split the sequence into two halves, count inversions in each half recursively, and count cross-inversions between the two halves, similar to mergesort.

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

What is the significance of log(n!) in the context of sorting lower bounds?

A

log(n!) represents the minimum number of comparisons required to sort “n” elements, resulting in a lower bound of O(n log n) for comparison-based sorting algorithms.

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

Explain the lower bound concept for sorting and searching algorithms.

A

The lower bound is based on information-theoretic arguments; for instance, sorting requires O(n log n) comparisons because each comparison only provides a binary answer.

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

How does Bucketsort achieve O(m + n) time complexity, and in what cases is it optimal?

A

Bucketsort works in O(m + n) when elements are uniformly distributed across a fixed range of size “m,” ideal for datasets with known ranges or uniformly distributed values.

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

What is the optimal time complexity for finding the median in the “Center of a Point Set on the Line” problem?

A

The optimal point minimizing the sum of distances to given points on a line is the median, achievable in O(n) time for selection without full sorting.

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

What are the main differences between in-place and non-in-place algorithms?

A

In-place algorithms (e.g., Quicksort) require only constant extra memory, whereas non-in-place algorithms (e.g., Mergesort) may need additional memory for auxiliary arrays.

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

How does using random pivots in Quicksort help achieve expected O(n log n) complexity?

A

Random pivots reduce the likelihood of extremely unbalanced splits, creating balanced partitions on average and preventing the worst-case O(n^2) complexity.

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