Use Selection Son to son the following array by hand. Show the steps for each it
ID: 3583160 • Letter: U
Question
Use Selection Son to son the following array by hand. Show the steps for each iteration (pass). List[0] 43 List [1] 21 List [2] 48 List [3] 1 List [4] 51 List [5] 19 Total number of comparisons: Number of iterations: An array is declared by: double X[4][5]; Suppose that the values in the array are stored in memory in the following order: 3 -1 2 -7 14 8 6 21 -10 -11 -25 0 -8 12 16 29 -19 -5 1 7 3. Draw a diagram of the array in table form, showing the values in their places. What value is stored at X(2](3]? How many bytes of memory does each value occupy? If the start address of the array is 3500, what is the memory address of X[2][3]? Show your reasoning!Explanation / Answer
Simple Algorithm for Selection Sort:
2. Elements exchanged in each iteration is shown in bold
Total number of comparisons in selection sort = n(n-1)/2 = 6*5/2 = 15
Total number of iterations = n-1 = 6-1 = 5
3. In C, Array elements are stored in row major order. When filling array elements, elements of array will be filled row wise.
double X[4][5]; //X is an Array with 4 rows and 5 Columns
a. Representation of elements in X
b. Value stored at X[2][3] = Value at Row 2,Column 3 = 12
c. Since each variable is of type double, each value would occupy 8 bytes
d. Each element would occupy 8 bytes. Each row contains 5 elements, hence each row would occupy 40 bytes.
Assuming the address of the array 3500 is in base 10.
X[2][3] = 3500 (base address of the array) + 2*40 (size of row) + 3*8(size of elements)
= 3500 + 80 + 24
= 3604 (Base 10)
list[0] list[1] list[2] list[3] list[4] list[5] Initially 43 21 48 1 51 19 Iteration 1 1 21 48 43 51 19 Iteration 2 1 19 48 43 51 21 Iteration 3 1 19 21 43 51 48 Iteration 4 1 19 21 43 51 48 Iteration 5 1 19 21 43 48 51Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.