Algorithms Terminology – Is ‘Read User Input’ a Step?

algorithmsterminology

Based on this definition of algorithm from Wikipedia:

In mathematics and computer science, an algorithm is a self-contained step-by-step set of operations to be performed. Algorithms exist that perform calculation, data processing, and automated reasoning.

An algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed, proceeds through a finite number of well-defined successive states, eventually producing "output" and terminating at a final ending state.

Is "Wait for user input" or simply read() counted an step of algorithm?

I thought for the following reasons it may not fit in the definition:

  • It seems it's not an step which can be executed as an operation is executed.
  • It should wait for an external signal to get finished, it could be against of the self-contained in the definition.
  • Moreover the definition talks about an initial input, so I suppose the input should be already provided.

Am I correct?

Update: If it's not an step, then how would you represent the following sequence, is it an algorithm?

  • X = 5
  • Y = X + 4
  • if ( Y > 10) Z = Read() // get the user input
  • else Z = 1
  • if (Z > 2) Z = Z + X

Please note reading occurs conditionally, then we may not suppose the input should be already provided.

Best Answer

That definition of "algorithm" is extremely narrow. It applies only to non-interactive deterministic digital small-step algorithms.

However, algorithms need not be digital (consisting of discrete steps and operating on discrete values). They can also be continuous (consisting of discrete steps and operating on continuous values) or analog (continuous progress and operating on continuous values). They can be non-deterministic (actually, it turns out that non-determinism is just a form of interactivity). They can be interactive (i.e. interacting with an environment). They can be parallel (i.e. wide-step).

For example, the simple "bucket-of-rain" algorithm. This is an interactive digital small-step algorithm:

  1. every morning at 8:00 am you put a bucket in the yard.
  2. every evening at 8:00 pm you measure the amount of rain in the bucket, in grams, truncated down to an integer.

This is a perfectly valid algorithm. It even has steps and operates on discrete values (which isn't even necessarily required for it to be considered an algorithm).

It is, however, interactive. It depends on some environment outside of the algorithm. Mathematically, in algorithm theory, this is modeled as an oracle.

So, to answer your question: yes, what you have there, is an interactive algorithm, and the reading is definitely a part of it.

Related Topic