From what I understand the insertion sort does use swapping however, unlike selection sort, it does the swaps by "shuffling" the element into the correct position which means it basically does a comparison with the element next to it and if it's smaller or greater than the element next to it the two elements swap and this will repeat until the element is in the correct position.Hi! Why does insertion push elements rather than swap each and why does selection swap elements rather than push. Or why don't they both push / swap? Is there a difference in pushing/swapping values
This sounds a bit more like bubble sort to me?it basically does a comparison with the element next to it and if it's smaller or greater than the element next to it the two elements swap and this will repeat until the element is in the correct position.
It is, my brain decided to forget about the unsorted/sorted part of insertion sort .This sounds a bit more like bubble sort to me?
well selection just finds the min/max and swaps, then finds the second min/max and swaps etc. whereas insertion creates a sorted subarray inside the array, and then from here pretty much acts like a bubble sort that only sorts the element adjacent to the sorted subarray to grow the sorted subarray by one element each iteration. i've never heard the word "push" used to describe either, both involve swapping. they're just different approaches to sorting, theres no one way to do it, if they both pushed/swapped or wtv then might as well write the same algorithm again and again lolHi! Why does insertion push elements rather than swap each and why does selection swap elements rather than push. Or why don't they both push / swap? Is there a difference in pushing/swapping values
My understanding was that it does not bubble up when moving the min/max, but instead shifts all elements to make room. But online there are resources showing both. So i'd probably go with whatever the HSC textbooks say and your teacher shows you, jchips' resource shows the shifting version.whereas insertion creates a sorted subarray inside the array, and then from here pretty much acts like a bubble sort that only sorts the element adjacent to the sorted subarray to grow the sorted subarray by one element each iteration.
In CompSci, push can have a very specific meaning for putting an element at the start of a stack or back of a queue. Insert is a bit more accurate here.I think it 'pushes' by incrementing/decrementating the index value of each unsorted element.
yes it’s not exactly a bubble, however from memory i believe some resources used a bubble sort to add a new element to the sorted subarray by swapping all the elements, whereas in reality you should really be finding the correct index then inserting the new element there hence the name. the hsc course specs actually show the insertion pseudo code correctly however i don’t think i was marked down by just swapping the elements instead of inserting in papers, as long as u grow the sorted sub array one by one.My understanding was that it does not bubble up when moving the min/max, but instead shifts all elements to make room. But online there are resources showing both. So i'd probably go with whatever the HSC textbooks say and your teacher shows you, jchips' resource shows the shifting version.
Bubbling is a very distinctive part of bubble sort (just as selecting the min/max is a distinctive part of selection sort), so I'd be worried about using an explanation of insertion sort that involved bubbling tbh. But definitely the important part is that the insertion sort is moving the next unsorted element into the sorted subarray.