1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the theoretical lower bound for any comparison-based sorting algorithm?
\Omega(N \log N)
This is the "speed limit" for sorting. It means that for a large input of size N, any algorithm that relies on comparing elements will require, in its worst-case scenario, a number of comparisons that grows at least as fast as N \log N.
What is the core idea behind the \Omega(N \log N) lower bound proof?
The proof uses a decision tree model to represent the sorting process.
true
/false
), the height of this decision tree (representing the worst-case number of comparisons) must be large enough to accommodate N! leaves (outcomes). This leads to a height of at least \log_2(N!) , which is in \Omega(N \log N) .Reproduce the proof that any comparison-based sort requires \Omega(N \log N) comparisons in the worst case.
Intuition: An algorithm must gather enough information to distinguish the correct sorted order from all N! possibilities. Each comparison provides one bit of information, forcing the number of steps to be at least the logarithm of the number of possibilities.
Formal Steps:
a[i] < a[j]
), and each leaf is a unique permutation representing the sorted output.Describe the core mechanism of Selection Sort.
Selection Sort divides the array into a sorted part (left) and an unsorted part (right).
Trace the execution of Selection Sort on the array [S, O, R, T]
. Show the state of the array after each swap.
[S, O, R, T]
[S, O, R, T]
(it's 'O'). Swap with the first element 'S'.[O, S, R, T]
[S, R, T]
(it's 'R'). Swap with the second element 'S'.[O, R, S, T]
[S, T]
(it's 'S'). Swap with the third element 'S'.[O, R, S, T]
(no change)[O, R, S, T]
What are the number of comparisons and exchanges for Selection Sort on an array of size N?
This makes its performance insensitive to the input's initial order. It performs the same number of comparisons regardless of whether the array is sorted or not.
What is the time complexity (Best, Average, Worst) of Selection Sort?
What is the primary advantage and disadvantage of Selection Sort?
Describe the core mechanism of Insertion Sort.
Insertion Sort divides the array into a sorted part (left) and an unsorted part (right).
Trace the execution of Insertion Sort on the array [S, O, R, T]
.
[S, O, R, T]
[O, S, R, T]
[O, S, R, T]
[O, S, R, T]
[O, S, R, T]
Describe the best-case scenario for Insertion Sort and its performance.
Describe the worst-case scenario for Insertion Sort and its performance.
What is the primary advantage and disadvantage of Insertion Sort?
Describe the core "Divide and Conquer" strategy of Merge Sort.
The actual sorting work happens exclusively during the merge phase.
What is the time complexity and space complexity of Merge Sort?
What is the primary advantage and disadvantage of Merge Sort?
Compare Selection Sort and Insertion Sort based on data movement (exchanges). When is this difference critical?
Conclusion: Selection Sort is preferable when write/swap operations are significantly more expensive than read/comparison operations. For example, when sorting very large objects where moving them in memory is costly, or when writing to a medium like flash memory where write cycles are limited.
Which of these algorithms (Selection, Insertion, Merge) is "adaptive," and what does that mean?