Question

A programmer is debugging a Selection Sort implementation. They notice that after the first pass, the smallest element is correctly placed at the beginning, but subsequent passes do not consistently place the next smallest element. What is a common logical error that could cause this?

A The inner loop for finding the minimum element starts from the beginning of the array in every pass. Correct Answer Incorrect Answer
B The swap operation is performed only if the minimum element is not already in its correct position. Correct Answer Incorrect Answer
C The outer loop iterates n times instead of n-1 times. Correct Answer Incorrect Answer
D The index of the minimum element is not correctly updated within the inner loop. Correct Answer Incorrect Answer
E The array is not initialized with distinct values. Correct Answer Incorrect Answer

Solution

The correct answer is D

Practice Next
ask-question