+ 2
Why does swap function from stl when used in selection sort increases the execution time from 19900 ns to 2 ,3 times much?
2 Answers
+ 1
My best guess is because std::swap introduces a time overhead of two function calls,std::swap itself and std::move.
Considering that the swapping step of the selection sort algorithm runs in O(n^2) in the worst case scenario,then it's easy to see why that small overhead quickly grows into some noticeable delay.
+ 1
Anthony Maina makes sense ,thank you :)