How To Build An Algorithm | The Science



The Science

How to build an algorithm

First and foremost, the ability of the programmer - create an algorithm. Knowledge of language is the second case, their choice - almost a matter of taste. But the basics are the same algorithmization always.

How to build an algorithm

Instruction how to build an algorithm

Step 1:

Learn the basic elements and symbols in the algorithm. First, you can however, seem out of place and it is difficult, as you need to write something truly three-dimensional and complex, you feel yourself that canonical algorithm shown are easy to read. Boxes indicate data creation and a new process of data entry - a parallelogram, a rhombus - condition. The cycle begins hexagon, use subroutines - a rectangle with optional side stripes. The beginning and end - the circle. Output values ​​obtained - "ragged sheet", the bottom side in the form of rectangular wave.

Step 2:

Cut! The main requirement for any algorithm is its simplicity. The lower elements in your design, the more reliable it will work. Moreover, accustom themselves to the fact that after the preparation of the original version, it should be possible to exclude from 2-3 extra step. Try to "pull yourself on the weak," and think of the process of reducing algorithm like a challenge rather than a stimulus. Remember - the shorter it looks in theory, the easier it is to write a program.

Step 3:

Prefer "dropouts" "fork". A far more convenient in terms of software code, typically a check conditions. In other words, aim for a more "direct" structure rather than branched. A classic example of the problem the algorithm will "determine the quadrant in which the point of the coordinates." In this case, the algorithm would be better composed of conditions: «xgt; 0, ygt; -danet 0», «x0 -danet" etc. Less would be a convenient option: "If xgt; 0, then ..." in most languages ​​it will take more steps to perform.

Step 4:

Carefully review the available libraries. Many novice programmers sin that does not know the basic commands even the built-in libraries, which is why they always have to reinvent the wheel. It is possible (especially when working with text, for him there is a huge stock of different commands) that some action (for example a comparison of the length of the rows) can be executed routines. This immediately rules out 5-7 extra steps out of your algorithm.