Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which sorting algorithm produces these steps?

Tags:

sorting

This was a multiple-choice question in an exam today, and (at least) one of the answers should be true, but to me they all look 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 and Quick Sort.

like image 513
Falkha Avatar asked Nov 27 '22 04:11

Falkha


1 Answers

I think that is a Quick sort. Here we can see the following steps:

  • A random selection of the reference element in the array (pivotValue), with respect to which reorders the elements of the array.

  • Move all of the values that are larger than the reference to the right, and all the values that the lower support left

  • Repeat algorithm for unsorted the left and right side of the array, while each element will not appear on its position

Why I think so:

It definitely isn't a Bubble Sort because it compares the first two elements of the array beginning so, the first step should be 2 5 6 1 3 4

It isn't a Insertion Sort because it's a sequential algorithm. In the first step we see that compared the first and the last element

It isn't a Selection Sort because it find the lowest value and move it to the top so, the first step should be 1 5 2 6 3 4

It isn't a Merge Sort because the array is divided into two subarrays. In this case we see interaction "first" and "second" parts

like image 200
Roman Marusyk Avatar answered Jun 17 '23 21:06

Roman Marusyk