Three problems about moving values around inside a list — Activity 2.12, in exam notation. The third shows one of the biggest differences between exam notation and C# in the whole course, and it is worth more than the other two put together.
Work these on paper. There is no computer on exam day.
aList ← bList assigns a COPY of bList: changing one does NOT change the otheraList[i] the element at i; THE FIRST IS aList[1]aList[i] ← x store x at position iaList[i] ← aList[j] copy one element onto anotherLENGTH(aList) how many elementsFOR EACH item IN aList first to lastREPEAT UNTIL(condition) repeats UNTIL it becomes trueDISPLAY(expression) show it, FOLLOWED BY A SPACEWhat does this display?
aList ← [7, 2, 9, 4]temp ← aList[1]aList[1] ← aList[3]aList[3] ← tempFOR EACH item IN aList{ DISPLAY(item)}Then answer this: delete the second and fourth lines, so only aList[1] ← aList[3] is left of the swap. What does the list hold now, and which value is gone for good?
This is one pass of selection sort. What does it display?
aList ← [42, 17, 93, 8, 55]smallest ← 1j ← 2REPEAT UNTIL(j > LENGTH(aList)){ IF(aList[j] < aList[smallest]) { smallest ← j } j ← j + 1}temp ← aList[1]aList[1] ← aList[smallest]aList[smallest] ← tempDISPLAY(smallest)FOR EACH item IN aList{ DISPLAY(item)}Then answer this: the list is not sorted when this finishes. How many more passes would selection sort make, and which position does the next pass fill?
aList gets sorted. What do the two loops at the bottom display?
bList ← [5, 1, 3]aList ← bListi ← 1REPEAT UNTIL(i > LENGTH(aList) - 1){ smallest ← i j ← i + 1 REPEAT UNTIL(j > LENGTH(aList)) { IF(aList[j] < aList[smallest]) { smallest ← j } j ← j + 1 } temp ← aList[i] aList[i] ← aList[smallest] aList[smallest] ← temp i ← i + 1}FOR EACH item IN aList{ DISPLAY(item)}FOR EACH item IN bList{ DISPLAY(item)}Then answer this, and it is the whole problem: in C#, the first two lines would be written like this.
int[] bList = { 5, 1, 3 };int[] aList = bList;The C# program would display something different for bList. Say what, and why — Activity 1.23 is where you met this. Then say which answer the exam expects.
bList displays: exam notation and C#This is graded on completion, not accuracy. Show your working — a wrong answer with visible reasoning is worth more to both of us than a right one with none.