Sorting Algorithms – Insertion Sort vs Merge Sort Memory Access

accessalgorithmsmemorysorting

I am a computer science sophomore doing a data structures and algorithms course. My professor said that insertion sort requires random access, while merge sort does not.

According to him, the insertion step in insertion sort requires random access. But can't it be implemented using sequential access in a linked list, going through each element, and as soon as you find that the element of the next node is more than the element you wish to insert, you squeeze that element after the current element (for ascending order list).

He is almost never wrong, but he also doesn't entertain doubts, due to which I'm forced to ask here. Please let me know. Thanks!

Best Answer

Ok, so I asked this question on the theoretical CS stack exchange website.

Louis has given what I think is the most suitable answer to this question:

Your implementation of linked lists also needs to be able to access memory non-sequentially for the pointer operations that splice in the new value.

That is, when I am inserting a new node at an arbitrary location in the linked list, I am assuming I have random access. Else, I would have to shift all the subsequent nodes ahead in memory before adding the new one.