How to construct an algorithm

How to construct an algorithm

The first and most important ability of the programmer - to make an algorithm. Knowledge of language it already the second business, their choice - practically a matter of taste. And here bases of algorithmization are uniform always.

Instruction

1. Study basic elements and designations in an algorithm. At first it can seem to you difficult and inappropriate, however, as soon as you need to write something really volume and complex, you will feel that it is kanonichno easy to read the represented algorithm. The rectangle designates formation of data and new process, data input – a parallelogram, and a rhombus – a condition. The cycle begins a hexagon, use of the subprogramme – a rectangle with additional strips sideways. The beginning and the end – a circle. A conclusion of the received values – "the torn-off leaf", a rectangle with a bottom side in the form of a wave.

2. Reduce! The main requirement to any algorithm is its simplicity. The less elements in your design, the it will be more reliable to work. Moreover, accustom yourself that after drawing up initial option, it will be for certain possible to exclude from it 2-3 excess steps. Try "to dare yourself", and perceive process of reduction of an algorithm as a certain call, but not an irritant. You remember – the shorter everything looks in the theory, the writing of the program will be simpler.

3. Prefer "elimination" to "fork". In terms of the program code the check of conditions, as a rule, is much more convenient. In other words, you strive for more "direct" structure, but not branched. The algorithm of a task "will serve as a classical example to define a quarter of the plane in which there is a point, on coordinates". In this case better there will be an algorithm made of conditions: "x> 0, y> 0 – dant", "x <0, y> 0 – dant", etc. Less convenient will be an option: "if x> 0, then …", in the majority of languages he demands more steps for performance.

4. Attentively study available libraries. Many beginning programmers sin with the fact that they do not know the main teams even of the built-in libraries because of what they constantly should invent the bicycle. Quite perhaps (especially during the work with the text, for it there is a huge stock of various teams) that some operation (for example comparison are long lines) can be performed by the standard subprogramme. It excludes 5-7 excess steps from your algorithm at once.

Author: «MirrorInfo» Dream Team


Print