Home > other >  Insertion sort recursive algorithm compared with non-recursive algorithm (runtime)
Insertion sort recursive algorithm compared with non-recursive algorithm (runtime)

Time:10-14

Insertion sort is more classic sorting algorithm, which is a stable site sorting algorithm, which means that it will not change the input has been orderly sequence between elements,
Its basic idea is: select an element, it is like a card from the pile, or compared with elements in front of it one by one, to find the right position, then insert, because the position of the selected elements may be other elements, so every time to compare all the selected elements should be before the element to the vacancy left by the selected element moving (to take a seat to insert the selected elements),
We need to compare the two algorithm running time, so you need to call time function of the system, and there is time. The perf_counter (), returns a CPU level of precise time count, the unit is in seconds (s), due to the short program instruction execution time, if you need accurate to milliseconds (ms), only need time. Perf_counter () * 1000,
  • Related