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.
B The swap operation is performed only if the minimum element is not already in its correct position.
C The outer loop iterates n times instead of n-1 times.
D The index of the minimum element is not correctly updated within the inner loop.
E The array is not initialized with distinct values.
Practice Next

Hey! Ask a query