Solve your doubts and expand your knowledge with IDNLearn.com's extensive Q&A database. Our community provides accurate and timely answers to help you understand and solve any issue.
Sagot :
Answer:
c. 3
Explanation:
The line of code on line 19
elements[minIndex] = temp;
will run a total of 3 times in with this call to the selectionSort method. The first time it will turn the 10 in position 2 into a 30. The second time it will turn the 20 in position 4 into a 40. Finally, it will turn the newly positioned 40 in position 4 into a 50. Therefore, completely sorting the array's elements.
The statement elements[minIndex] = temp; in line 19 of the method is executed 3 times as a result of the call to selectionSort
The array is declared as:
int[] arr = {30, 40, 10, 50, 20};
To sort the above array, the selectionSort algorithm would
- swap the positions of 10 and 30
- swap the positions of 20 and 40
- swap the positions of 50 and the new position of 40
Hence, the selectionSort algorithm would execute line 19 3 times
Read more about algorithms at:
https://brainly.com/question/15263760
Your participation is crucial to us. Keep sharing your knowledge and experiences. Let's create a learning environment that is both enjoyable and beneficial. Thank you for choosing IDNLearn.com for your queries. We’re here to provide accurate answers, so visit us again soon.