Algorithm 2: in-place selection sort
The second algorithm is in-place selection sort, as described infigure 5.3 on page 124 of ADITA 0.9.10. This code will be longer,but can be a direct translation of the pseudocode in figure 5.3into C++ code.
Selection sort takes O(n2)time, but it is very simple and avoidsexpensive operations such as memory allocation, recursion, andgenerating random numbers. Therefore we expect it to have the bestconstant factors of all four algorithms. Hypothesis 1 suggests thatselection sort will be fastest for very small n, perhaps n100.However our theory predicts that the other O(n n)-timealgorithms will be faster for large n.
Implement it
OR
OR