- 2068 Bhadra · 2 marks
Efficiency of straight selection sort
Short answer
Straight selection sort performs (n^2 - n)/2 comparisons, always O(n^2). Best, average, and worst case are O(n^2), with O(1) extra space.
Calculate efficiency of straight selection sort.
Straight selection sort finds the smallest element of the unsorted part in each pass and swaps it into its place.
For n elements, pass 1 makes n−1 comparisons, pass 2 makes n−2, ..., and the last pass makes 1:
(n−1) + (n−2) + ... + 1 = n(n−1)/2 = (n² − n)/2
So the number of comparisons is about n²/2 in every case (best, average and worst), because the whole unsorted part is always scanned. Swaps are at most n−1.
Answer: time complexity is O(n²) in all cases; extra space is O(1).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Straight selection sort on 33, 90, 45, ... · Data Structure and Algorithm, chapter 7
- Selection sort with trace · Data Structure and Algorithm, chapter 7
- Efficiency of quick sort · Data Structure and Algorithm, chapter 7 · asked 2×
- Ampere's law, field of straight wire · Engineering Physics, chapter 8 · asked 5×
- Camber elevations, straight and parabolic · Transportation Engineering I, chapter 3
- Max height of straight draft tube (Francis) · Hydropower Engineering, chapter 7