Do algorithms always produce the same output given a certain input?


#1

Question

In the context of this exercise, do algorithms always produce the same output given a certain input?

Answer

No, sometimes an algorithm might produce a different output when given the same input.

This relates to the area of deterministic and non-deterministic algorithms.

A deterministic algorithm will always produce the same output given a certain input. For example, an algorithm to return the largest number of a list will always return the same value given the same input list.

For instance,
greatest_value([1, 2, 3, 4])
will always give us 4 as the output value.

Non-deterministic algorithms can produce a different output given the same input, each time you run such an algorithm. This is usually due to some level of probability or randomness.