One Irish Rail delay is out of order. How much of the list do you need to move?
Your Irish Rail app lists delays of eight, twelve, five, fourteen and sixteen minutes. You want the shortest delay first. Five is out of place. If you slide it into the right spot, which entries actually have to move?
If eight is the only delay on your screen, it's already in order because there's nothing to compare it with. With several delays, shortest first means each value is at least as big as the one before it.
Start with eight on its own. Twelve stays after eight. Next, watch five go before both of them. The ordered part now starts with five, eight and twelve. When you reach fourteen and then sixteen, each is already in the right place, so neither needs any entries to shift.
Start with the list twelve, eight, five, fourteen. Treat twelve as sorted on its own, then insert only the next item, eight. That's one pass. What does the whole list look like now? Pick one answer.
In insertion sort, the ordered part at the front is the sorted prefix. Save the next value as the key. Scan the prefix from right to left, shifting each larger value one place right. Stop when you run out of entries or find one no larger than the key. Fill the gap.
Eight and twelve are in order. The bar marks where the untouched suffix starts. Save five as the key, and use a square for the slot to fill. Shift twelve right, then eight. Put the saved five in the gap at the start. Fourteen and sixteen stay untouched.
Now the sorted prefix is three, seven, eleven. Your next key is six and fifteen is still waiting. Think through which values shift right. What does the whole list look like after inserting just six? Pick one answer.
Both sides start with the same list. On the left, copying eleven right overwrites six. On the right, you save six before copying eleven. Both lists now show two elevens, but only on the right do you still have six ready to insert.
Nearly sorted: one shift, five value comparisons. Reverse order: ten of each. Already sorted: no shifts, four comparisons. Standard selection sort makes ten comparisons for each list because it scans the unsorted part every pass. As the list grows, insertion sort takes linear time on sorted data and quadratic time in the worst case.
If you're asked to show the contents of the list after each pass, write one row for each completed insertion. Start with six alone. Nine stays put, three goes before six, then seven goes between six and nine. Read the prefix and suffix together to get the whole list.