c++ programming questions: The selection sort continues until ______________ of
ID: 3863408 • Letter: C
Question
c++ programming questions:
The selection sort continues until ______________ of the n items in an array have been swapped. a) n/2 b) n - 2 c) n - 1 d) n Given the following array: 4 15 8 3 28 21 which of the following represents the array after the second swap of the selection sort? a) 4 3 8 15 21 28 b) 4 15 8 3 21 28 c) 3 4 8 15 21 28 d) 21 4 3 8 15 28 Given the fact that a selection sort of n items requires n^2/2 + 5 * n/2 - 3 major operations, the selection sort is ___________. a) O(1) b) O(n) c) O(n^2) d) O(log_2 n) The compares adjacent items and exchanges them if they are out of order. a) selection sort b) binary search c) bubble sort d) quicksortExplanation / Answer
14. The selection sort continues until ___ of the n items in an array have been swapped.
c) n-1. If n-1 elements are swapped, the last element is obviously in the extreme position,
therefore, the whole list is sorted.
15. Given the following array:
4 15 8 3 28 21
which of the following represents the array after the second swap of the selection sort.
For the first loop, select the largest element 28, and swap with last element.
So, the list is now, 4 15 8 3 21 28
For the second loop, select the largest element 21, and no swap is required here,
as the last element itself is the largest element.
For the third loop, select the largest element 15, and swap with the third largest element.
So, the list is now, 4 3 8 15 21 28.
The answer is: a. 4 3 8 15 21 28.
16. Given the fact that a selection sort of n items requires n^2/2 + 5 * n/2 - 3 major
operations, the selection sort is:
c. O(n^2).
17. The ___ compares adjacent items and exchanges them if they are out of order.
c. Bubble sort. This is what it does: if(a[j] > a[j+1]) swap(a[j], a[j+1])
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.