Are all algorithms this complex?

Question

In the context of this exercise, are all algorithms as complex or long as the ones provided?

Answer

No, algorithms can be much simpler, but also even more complex than the ones provided in this exercise.

By its definition, an algorithm is just a step-by-step solution to a general type of problem, which usually takes some input, and provides an output.

One simple algorithm might be finding the average of two numbers.

sum = num1 + num2
answer = sum / 2.0

How complex an algorithm is will usually depend on how complex the problem being solved is. For instance, machine learning typically requires complex algorithms that apply different areas of mathematics and might require dozens of lines of code to write.

6 Likes