Question 4/371: What algorithm does the following pseudocode perform? Declare in
ID: 3555651 • Letter: Q
Question
Question 4/371: What algorithm does the following pseudocode perform?
Declare integer startScan
Declare Integer minIndex
Declare Integer minValue
Declare Integer index
For startscan = 0 To arraySize -2
Set minIndex = startScan
Set minValue = array[startScan]
For index = scartScan + 1 To arraySize -1
If array[index] < minValue
Set minValue = array[index]
Set minIndex = index
End if
End For
Call swap(array[index], array[startScan])
Explanation / Answer
Annswer : Selection Sort
The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.