Insertion Sort Animation

Insertion Sort Animation



welcome back everyone today I want to talk about insertion sort insertion sort is a simple sorting algorithm on arrays now insertion sort works similar to picking up a deck of cards are picking up cards from a deck and sorting them as you pick up each card by swapping them until you get the right order in this order we're working from ascending orders from so from left to right the order should be ascending I start with a simple array here of these numbers the first thing I'm gonna do here in my assertion sort isn't gonna look at the first number which is 55 then I have that in my hand as you should think of it since I only have one part in my hand it's sorted then I look at my second card alright pick up the second item in the array which is 34 since now this is in my hand I swapped them because they are not in order 34 is less than 55 so I swapped them to make sure my hand is in order this leaves me with my next element 12 which is at the bottom of the array so I swap it with 55 and then swap it with 34 so now my hand is in ascending order again from left to right so now my incision insertion order is swapped in place then I take 46 and swap it with 55 I don't swap 46 with 34 because the array is in order now so now I kept my arrays in order it's perfect and insertion sort has worked so insertion sort again works by picking up or looking at each item in the array one by one and then swapping it to the left if it is greater than if it is less than the number to the left of it if it's the greatest element you can just leave it be thanks for watching guys and like this video if you really liked it smash that like button

Leave a Reply

Your email address will not be published. Required fields are marked *