The algorithm of any complexity can be provided by a combination of three basic structures:
• Composition or followings;
• branching (alternative, if – that – differently);
• Iteration or a cycle (with a precondition, with a post condition, with a finite number of repetitions).
Characteristic of these structures is existence at them one input and one output.
First basic structure. The basic structure «composition or following» means that some operators shall be executed sequentially one after another and only once for runtime of this program. Set of the connected units of structures of «following» is called as the linear computing algorithm.
The operator is understood as the formal record of the instruction for execution of some sequence of actions.
Second basic structure. The second basic structure is «the alternative or branching». This structure provides, depending on result of check of a condition (it is true or lie), the choice of one of alternate ways of operation of algorithm, and each of ways carries to the general output.
Possible ways of execution of algorithm mark with the appropriate labels: truth/lie, yes/no, 1/0.
In that specific case it can appear that for one of the selected ways of actions it is not necessary to undertake. Such structure received the name «bypass» or structure «if».
The algorithm which composition includes basic structure «alternative or branching» is called as branching.
If in algorithm there are three and more directions of branching, it is possible to provide it in the form of set of several basic structures «if – that – differently». Such variety of structure «ramifying often» calls «multiple selections».
Third basic structure. Third basic structure «cycle». The cycle provides repeated execution or, in other words, cyclical operation of operators.
Distinguish three varieties of this structure:
•«a cycle – while»
•«a cycle – to».
• finite number of repetitions.
Group of the operators repeating in a cycle, are called as a cycle body. The main difference of structure «a cycle – while» from structure «a cycle – to» is that in the first structure operators of a cycle body depending on a condition cannot be executed absolutely whereas in structure «a cycle – to» the loop body will be executed at least once. It is possible to note that in structure «a cycle – while» check of execution of a condition is carried out before execution of operators of a cycle body, and in structure «a cycle – to» – after cycle body passing.
Cycles can contain in themselves other cycles. Such structures are called as nested cycle. The algorithms incorporating basic structure «cycle» are called as cyclical.
The considered basic structures are recommended to apply to observance of a structural campaign to algorithm elaboration. Real algorithms represent set of all considered basic structures. The cycle with the given number of repetitions (a calculating cycle) – designates repetition of some actions the specified number of times.
Properties of algorithm
Discretization (in this case, a divided on a part) and orderliness. The algorithm shall consist of separate actions which are executed sequentially one after another.
Determinacy (single-digit determinacy). Repeated application of one algorithm to the same set of basic data always yields the same result.
Formality. The algorithm shall not allow ambiguity of interpretation of actions for the performer.
Productivity and extremity. Operation of algorithm shall come to the end for a certain number of steps, thus the task shall be decided.
Mass character. A certain algorithm shall be applicable to all same tasks.
Develop can invent algorithms with only reasonable beings (for example, the person). And here it is formal (without thinking and without evaluating) to execute, any machines (for example, computers, household appliances). The matter is that the person is released from routine activities which often can take a lot of time, and guarantees it with machines.
However machines not people: instruments understand only limited number of commands and can process these (objects) of not all types. From this it follows that the developer of algorithm finally shall describe algorithm in admissible commands of a certain performer (that machine to which algorithm execution will be entrusted). Set of commands which this performer can execute, is called as an instruction set of the performer. Objects (this) over which the performer can execute actions, create the environment of the performer.
Programming language – means of record of algorithms for computers
Universal performers are the computer. With its help it is possible to execute various algorithms by types: to do mathematical computation, to process text data, to change a graphics, etc. In any sense the computer can do a lot of things, as the person, and some things much quicker. However the person and the computer «talk» in absolutely different languages: one – on natural (Russian, English, etc.), and another – in the formal (machine) language.
Having developed algorithm, the person shall «explain» it to the computer somehow. For these purposes programming languages serve, and result of record of algorithm on them is the program.
Now the programming language is rather a certain intermediary between the person and the computer. The program written in a programming language, in a consequence is translated to a machine language by the translator.
The study of algorithms has the big practical significance. It is connected to that creation of algorithm assumes the detailed description of each step of the solution of the task, and finally the step of algorithm can be rather simple for execution by its computer. So tasks for which it is possible to work out algorithm of their decision, can be automated, i.e. are shifted «on shoulders» machines.
However it is necessary to remember always, what not all tasks have the algorithmic decision.
Thus for those tasks which after all have the algorithmic decision, different algorithms can be developed. But only one will be the most likely effective.