Sorting

AP Computer Science A· difficulty 4/5

Selection sort on n elements always performs approximately

  • A

    nn comparisons on a sorted input

  • B

    n!n! comparisons in the worst case

  • C

    n22\frac{n^2}{2} comparisons regardless of input order

    check_circle
  • D

    logn\log n comparisons in the best case

Explanation

Selection sort scans the unsorted portion fully each pass: n + (n-1)

<ul> <li>... + 1 ≈ n²/2 comparisons. Best/worst/average all O(n²); input order doesn't matter.</li> </ul>

Want 10 more like this — adaptive to your weak spots?

Related questions