Pascal. The concept of an algorithm. Ways to write algorithms. Classification of algorithms by structure. Algorithm Properties

The concept of an algorithm. Ways to write algorithms. Classification of algorithms by structure. Algorithm Properties


Search other websites:

1. What is an algorithm? The definition of the algorithm. Examples of algorithms

Every day a person sets himself different tasks, which he then solves. Some decisions are formed spontaneously, some follow a previously developed plan. In any case, a person seeks to achieve the desired result. In programming, to solve any problem, you first need to develop an algorithm.

Algorithm – an accurate and understandable instruction to the executer to make a sequence of actions aimed at achieving a specified goal or solving a task. A number of requirements are presented to the algorithm. The algorithm should be designed so that its implementation necessarily leads to the desired result.

Algorithm development is a creative process. For the same problem, a different number of algorithms can be developed that solve it. And, on the contrary, for some different types of tasks a generalized algorithm for solving them can be distinguished. The correct development of the algorithm depends on the correct operation of the program. If the complexity of the problem is high, then the execution of the algorithm requires more significant labor and time resources.

An example of an algorithm. Let the student need to write a report and print it on a home printer. A generalized algorithm for performing this work may be, for example, as follows:

  1. Familiarize yourself with the necessary materials, literature, etc.
  2. Turn on the computer.
  3. Download the text editor.
  4. Type or edit the text of the report.
  5. Turn on the printer.
  6. Print report.
  7. Reread the report again. If errors are found in the report, repeat steps 4-6.


2. Algorithm writing methods

There are three ways to write algorithms:

  1. Verbal – this is the case when the algorithm is described in ordinary language (human-readable).
  2. Graphic – the case when the algorithm is described using graphic notation. This is the most common way of writing an algorithm, which is indicated in the form of flowcharts.
  3. Character – a description of the algorithm using a character set.


3. Graphic way to write an algorithm. Designation on flowcharts

The most common way to write an algorithm is a graphical method in the form of a flowchart. A block diagram is a drawing consisting of geometric shapes (rectangles, parallelepipeds, rhombuses, ovals, etc.) that are connected by directional lines. Geometric figures (blocks) correspond to certain steps of the algorithmic process, and directional lines determine the execution order of blocks.

The geometric designations of the most common blocks are shown in Figure 1.

The geometric designations of the most common blocks that are used in flowcharts

Figure 1. The geometric designations of the most common blocks that are used in flowcharts


4. Classification of algorithms by structure

The following types of algorithms are distinguished:

  • linear algorithm – the case when the blocks of operations are performed sequentially one after another (Figure 2). In such algorithms, each stage of the calculation is reduced to the execution of a sequence of instructions that are executed once;
  • branched algorithm. In these algorithms, the course of solving the problem depends on the fulfillment (or not fulfillment) of a certain condition (Figure 3);
  • a cyclic algorithm is an algorithm in which one or another part of the calculations is performed repeatedly (Figure 4). The number of repetitions must be finite.

Linear algorithm

Figure 2. Linear algorithm

Branched algorithm

Figure 3. Branched algorithm

Loop algorithm

Figure 4. Loop algorithm


5. Algorithm properties

The following properties are distinguished for the algorithm:

  • certainty (accuracy) of the algorithm – the course of solving the problem should be accurate, understandable and exclude the possibility of arbitrary interpretation. The calculation process must be such that it can be repeated;
  • mass – the algorithm should be applicable to a number of similar tasks for which the initial conditions change;
  • discreteness. This is a partition of the problem into elementary operations to ensure its solution. One and the same problem can be solved in different ways. However, each of the methods breaks down the solution of the problem into several smaller subtasks;
  • potency – solving a problem should lead to some result;
  • correctness – due to the step-by-step execution of the algorithm, the correct result should be obtained.


Related topics