About insertion sort and especially why it's said that copy is much faster than swap?
- by Software Engeneering Learner
From Lafore's "Data Structures and Algorithms in Java":
(about insertion sort (which uses copy + shift instead of swap (used in bubble and selection sort)))
However, a copy isn’t as time-consuming as a swap, so for random data
this algo- rithm runs twice as fast as the bubble sort and faster than
the selectionsort.
Also author doesn't mention how time consuming shift is.
From my POV copy is the simplest pointer assignment operation. While swap is 3x pointer assignment operations. Which doesn't take much time. Also shift of N elemtns is Nx pointer assignment operations.
Please correct me if I'm wrong.
Please explain, why what author says is true? I don't understand.