Compare correct algorithms by the work they perform and the memory they use as the input grows.
An algorithm is a sequence of steps that solves a problem. Suppose you need the smallest reading in a nonempty list of sensor measurements. Before comparing solutions, agree on what they must return.
For [5, 2, 8, 1, 9], both of these methods return 1:
5 to 2, stays at 2 after seeing 8, drops to 1, then stays there after 9.For five readings, the scan needs four comparisons and one variable for the current minimum. For a million readings, it needs 999,999 comparisons and the same variable. Sorting the copy also puts every other value in order, and it reserves memory for another list. If the only question is “which is smallest?”, the scan already does all the work you need.