KnowledgeBoat Logo
|

Computer Applications

Show the contents of the array after the second iteration of Selection Sort.

1207122433114195163735869\underset{0}{\boxed{12}}\underset{1}{\boxed{7}}\underset{2}{\boxed{2}}\underset{3}{\boxed{43}}\underset{4}{\boxed{11}}\underset{5}{\boxed{19}}\underset{6}{\boxed{1}}\underset{7}{\boxed{3}}\underset{8}{\boxed{35}}\underset{9}{\boxed{6}}

Java Arrays

8 Likes

Answer

In the first iteration, the smallest element 1 will be swapped with the element at first index 12. The contents of the array after the first iteration of Selection Sort will be:

1071224331141951263735869\underset{0}{\boxed{1}}\underset{1}{\boxed{7}}\underset{2}{\boxed{2}}\underset{3}{\boxed{43}}\underset{4}{\boxed{11}}\underset{5}{\boxed{19}}\underset{6}{\boxed{12}}\underset{7}{\boxed{3}}\underset{8}{\boxed{35}}\underset{9}{\boxed{6}}

In the second iteration, the second smallest element 2 will be swapped with the element at second index 7. The contents of the array after the second iteration of Selection Sort will be:

1021724331141951263735869\underset{0}{\boxed{1}}\underset{1}{\boxed{2}}\underset{2}{\boxed{7}}\underset{3}{\boxed{43}}\underset{4}{\boxed{11}}\underset{5}{\boxed{19}}\underset{6}{\boxed{12}}\underset{7}{\boxed{3}}\underset{8}{\boxed{35}}\underset{9}{\boxed{6}}

Answered By

4 Likes


Related Questions