ITEC 2620 Chapter Notes - Chapter 1-10: Insertion Sort, Sorting Algorithm, Bubble Sort
Document Summary
We grab 2 card and sort them like 6th spade and ace. Insertion sort : inserting new value each time, take one slide it over to right, 21 17 16 2 . 21 17 , if 17 small we swap for 16 we don"t . Swapping one at time, elements can still move sorted among themselves. Selection sort : we find smallest value , move it to right , stuff on left not sorted. Disadvantages of sorting algorithm: we have two for loops, is this smallest value repeat. Disadvantages of insertion sort: worst case is that its inversely sorted. Third one takes 3 swap etc. average of n over 2 swap. Best case is next element sorted there are no swaps . In order to determine if we need swap we need to use comparison, one comparison each time in loop, first one sorted second all way until the end.