Use Selection Son to sort the following array by hand. Show the steps for each i
ID: 3583158 • Letter: U
Question
Use Selection Son to sort the following array by hand. Show the steps for each iteration (pass). 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 -1 -9 -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
question no. 2
list is as below
43,21,48,1,51,19
solution:
on iteration 1 look for smallest from 1st to 6th.swap 1 with 43
1) 1,21,48,43,51,19
on iteration 2 look for smallest from 2nd to 6th. swap 21 with 19
2) 1,19,48,43,51,21
on iteration 3 look for smallest from 3rd to 6th. swap 48 with 21
3) 1,19,21,43,51,48
on iteration 4 look for smallest from 4th to 6th. looks good no swap
4) 1,19,21,43,51,48
on iteration 5 look for smallest from 5th to 6th. swap 51 with 48.
5) 1,19,21,43,48,51
total no. of comparisons made = n(n-1)/2
=6(5)/2
=15
total no. of iterations: 5
question no. 3a.
Questin 3b.
valuestored at X[2][3]=21
Quesin 3c.
8 bytes of memory each value occupy
Question 3d.
first element address = 3500
x[2][3] address=3556
calculation...
there are 7 elements in between from starting element X[1][1]. Those are X[1][2],X[1][3],X[1][4],X[1][5],X[2][1],X[2][2],X[2][3]
each has memory of 8 bytes so 8*7=56 bytes X[2],[3] is far from X[1][1].
Therefore it has memory address 3500+56=3556
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.