Which of the following sort algorithms is represented in the pseudocode?

Loop while i < size - 1
index = i
Loop while j between(i + 1 and size)
if data[j] < data[index]
index = j
temp = data[i]
data[i] = data[index]
data[index] = temp
(1 point)
Responses

quicksort
quicksort

bubble sort
bubble sort

selection sort
selection sort

merge sort

1 answer

The pseudocode you provided represents the selection sort algorithm.

Here's a brief explanation of why this is the case:

  • The outer loop (while i < size - 1) iterates through each element in the array except the last one.
  • The inner loop (while j between(i + 1 and size)) finds the smallest element in the unsorted portion of the array.
  • It maintains an index variable to track the position of the smallest element found.
  • After the inner loop completes, the smallest element is swapped with the current position (i), which is characteristic of how selection sort operates.

Therefore, the correct response is selection sort.