Which sorting algorithm produces these steps? -


this multiple-choice question in exam today, , (at least) 1 of answers should true, me wrong.

the sorting steps are:
5 2 6 1 3 4
4 2 6 1 3 5
4 2 5 1 3 6
4 2 3 1 5 6
1 2 3 4 5 6

the available answers were: bubble sort, insertion sort, selection sort, merge sort , quick sort.

none of them.

  • bubble sort: no. after k steps, last k elements should k largest, sorted.
  • insertion sort: no. after k steps, k first elements should sorted.
  • selection sort: no. after k steps, k first elements should s smallest, sorted.
  • merge sort: no. after k steps, value can have moved 2^k - 1 places. (5 moves 5 places @ k=1)
  • quick sort: no. whatever pivot is, 1 , 6 being extreme values, can stay in initial position.

on quick sort: make clear not possible, lets enumerate results of each pivot first step:

  • 5 : [2134] - 5 - [6]. (2134 may in order)
  • 2 : [1] - 2 - [5634]
  • 6 : [52134] - 6
  • 1 : 1 - [52634]
  • 3 : [21] - 3 - [564]
  • 4 : [213] - 4 - [56]

one obvious way of seeing incompatible op's output in each case, 1 before 6, no matter how implement pivot or partition.


Comments