Complexity of sorting Flashcards

(18 cards)

1
Q

What is the time complexity of selection and insertion sort?

A

O(n²) — quadratic time.

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

What is the best known time complexity for comparison-based sorting?

A

Θ(n log n)

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

What does MergeSort’s time complexity show?

A

That it is asymptotically optimal among comparison-based sorting algorithms.

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

What theoretical tool do we use to analyze the lower bound of sorting?

A

A decision tree model.

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

How does a decision tree represent a sorting algorithm?

A

Each internal node is a comparison, and each leaf is a sorted permutation.

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

Why must a decision tree have at least n! leaves?

A

Because there are n! possible orderings of n elements.

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

What is the minimum height of a decision tree that sorts n elements?

A

log₂(n!)

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

What is the worst-case number of comparisons for any comparison sort?

A

At least Ω(n log n)

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

What is the lower bound for comparison-based sorting derived from log₂(n!)?

A

Ω(n log n)

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

Why can’t any comparison sort be faster than n log n in general?

A

Because it would violate the decision tree lower bound.

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

Why is MergeSort considered optimal in complexity?

A

Because it matches the Ω(n log n) lower bound in worst-case time.

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

What does MergeSort rely on for correctness?

A

Correctness of the merge operation and a loop invariant during merging.

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

What is a loop invariant in MergeSort’s merge step?

A

It ensures the result array always contains the smallest remaining elements from both input arrays.

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

What is the significance of the merge operation in MergeSort?

A

It guarantees that two sorted subarrays are merged into one sorted array.

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

Is Shellsort faster than insertion sort?

A

Yes — it reduces disorder with long strides, though worst-case is still suboptimal.

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

What is Shellsort’s worst-case complexity with better gap sequences?

17
Q

What happens if a sorting algorithm skips possible permutations in the decision tree?

A

It may fail to sort all inputs correctly.

18
Q

What does the decision tree lower bound prove about MergeSort?

A

That no other comparison-based sort can asymptotically beat its performance.