Sorting

AP Computer Science A· difficulty 2/5

// insertion sort on n elements, reverse-sorted input

What is the worst-case complexity?

  • A

    O(n log n)

  • B

    O(n)

  • C

    O(log n)

  • D

    O(n^2)

    check_circle

Explanation

Reverse-sorted input forces maximum shifts each iteration: O(n^2).

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

Related questions