3 ms·
Was the image the only description of the insertion sort algorithm you were given? If so, sounds like a pretty flawed interview process.
by brown9-2 15y ago
Was the image the only description of the insertion sort algorithm you were given? If so, sounds like a pretty flawed interview process.
- jerfelix 15y agoNot sure I agree. I wouldn't have been able to tell you what an insertion sort is, by name. But by looking at that image, I can describe it pretty well: Have an outer loop that counts from the first position in the list to the last position (call it n...). At each step in the loop, make sure that the first n items are sorted. This probably implies an inner loop that finds where, within the first n-1 items to insert the nth item. And given that with only one item, it's already sorted, we can probably start with n on the second item. Yeah, I think I could code that, given the image.