Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

FinalExam Review Fall2005: Explain the Sort

Questions? Comments? Answers?


A. Why does the position value start at 1? Why not 0?
In an insertion sort, the current value is compared to all values before it. If it was 0 there wouldn't be anything to compare it to and you would get a null pointer exception probably.

B. What's going on in the loop where Position A is?
It's comparing the values to see which one is greater

C. At Position B, what can we say about the values from 0 to position in the list?
Once it finds the position it is to go in, it places it in there and then continues with the next element. Since the sort goes from 0 to n step by step, for any given element you are sorting as you go up from 0, the elements before it will be sorted properly.

Kyle DuPont

A is right. B is close. C is wordy but gets to the right place. Mark Guzdial

B. It finds to see if they are sorted properly, if the element before is greater, then you move down one more, if it is less then you insert at that point

B. Its moving values down until it finds the A position
C. They are all in order or sorted Student161

Both B's are right, but C is only close. At Position B, the values 0..position are sorted, but no further – not from position+1 to the end of the array. Mark Guzdial