Q3: Reading Algorithms: The following algorithm (expressed in pseudocode) takes as input a list of numbers (e.g. {4, 5, 99, -4, 0} and {-2, 4} would both be valid inputs): //==========Start============ Let N be the number of items in the list. Do the following N times: Let I = 1 While (I < N) repeat the following: If the Ith number in the list is greater than the (I+1)th number then: Swap the Ith and (I+1)th numbers in the list. EndIf. Add 1 to I. EndWhile. EndDo. Print out the list. //==========END=============== ANSWER THE FOLLOWING for the pseudoc
This code switches two adjacent numbers if the greater number comes before the smaller number. So if the input list is {4, 5, 99, -4, 0} the resulting list would be {4, 5,-4, 0, 99} if the input list is {-2, 4} the resulting list would be {-2, 4}
3. What output does the algorithm give on input { 9, 10, -4, 9 } as the list?
the output would be { 9, -4, 9, 10}
Join our real-time social learning platform and learn together with your friends!