One problem, several algorithms
Goal: State what goes in and what must come out.
Suppose we want the average of three numbers. The three numbers are the input: the data we start with. Their average is the output: the result we must produce.
An algorithm is a clear set of steps that produces the required output and finishes for every input allowed by the problem. We can describe the steps in words before writing any C++ or Java.
There might be three different solutions: Algorithm A, Algorithm B, and Algorithm C. Before comparing their speed, ask: Do all three solve the same problem under the same conditions?
A small check before comparing solutions
A method that adds the three numbers but returns only their sum does not yet calculate their average. It must also divide the sum by 3. Finishing quickly does not make an incomplete answer correct.
This check separates the required result from the method used to produce it.
Is an algorithm just its code?
You describe a solution in words, then write it in C++. What can stay the same when you implement it in Java?
Remember: An algorithm needs clear steps, the correct result, and a stopping point.