Block diagram of operating principle. Create a simple flowchart. Algorithm flowcharts: examples

Block diagram we will call such a graphical representation of the algorithm when individual actions (or commands) are represented in the form of geometric figures - blocks. Inside the blocks information about the actions to be performed is indicated. The connection between blocks is depicted using lines called communication lines, indicating transfer of control.

There is a State Standard that defines the rules for creating flowcharts. The configuration of blocks, as well as the order of graphic design of block diagrams, are regulated by GOST 19.701-90 "Schemes of algorithms and programs." In table 2.1 shows the designations of some elements, which will be quite sufficient to depict algorithms when performing student work.

Rules for drawing up block diagrams:

    Every flowchart must have a block " Start" and one block " End».

    « Start" must be connected to the block " End» flow lines along each of the branches available in the block diagram.

    There should be no blocks in the block diagram, except for the block " End”, from which the flow line does not come out, as well as blocks from which control is transferred “to nowhere”.

    Blocks must be numbered. Numbering blocks are drawn from top to bottom and from left to right, the block number is placed at the top left, in the gap in its outline.

    Blocks are connected to each other by flow lines that determine the sequence of block execution. Flow lines should run parallel to the edges of the sheet. If the lines gofrom right to left ordown up , then arrows at the end of the line are required, otherwise you don’t have to install them.

    In relation to blocks, lines can be inbox And going out.

    The same flow line is outgoing for one block and incoming for another. Start From the block "

    "Unlike all other blocks, the flow line only comes out, since this block is the first in the block diagram. End Block "

    " has only an input since it is the last block in the flowchart.

    For ease of reading, it is desirable that the flow line enters the Process block from the top and exits from the bottom. To avoid cluttering the flowchart with complex intersecting lines, flow lines can be broken. In this case, at the site of the break, they place connectors

    In order not to clutter the block, you can provide information about the data, variable designations, etc. place in comments to the block.

Block name

Block designation

Purpose of the block

Terminator

Start/End of program or subroutine

Data processing (computational action or sequence of computational actions)

Branching, choosing, checking conditions. The block indicates a condition or question that determines the further direction of execution of the algorithm

Preparation

Counting cycle header

Predefined process

Referring to the procedure

Data input/output


Types of Algorithms

The type of algorithm is determined by the nature of the problem being solved in accordance with its commands. There are three types of algorithms: linear, branching, cyclic.

Linear algorithm consists of an ordered sequence of actions, independent of the values ​​of the source data, with each command executed only once strictly after the command that precedes it.

This, for example, is an algorithm for calculating using the simplest non-alternative formulas, which has no restrictions on the values ​​of the variables included in these formulas. Typically, linear processes are part of a more complex algorithm.

branching are called algorithms in which, depending on the value of some expression or on the fulfillment of some logical condition, further actions can be carried out in one of several directions.

Each possible direction of further action called branch.

In block diagrams, branching is implemented by a special block “ Solution". This block provides the possibility of two outputs. In the “Decision” block itself, a logical condition is written, the fulfillment of which determines further actions.

There are several types of branching algorithms.

1. "Bypass" – such a branch when one of the branches does not contain a single operator, i.e. as if bypassing several actions of another branch.

2. "Branching" – this type of branching when each branch contains a certain set of actions.

3. "Multiple Choice" – a special type of branching, when each of several branches contains a certain set of actions. The choice of direction depends on the value of some expression.

Cyclic algorithms are used in cases where it is necessary to implement repeatedly repeated calculations of the same type. Cycle is a sequence of actions that can be performed repeatedly, i.e. more than once.

There are:

      loops with a known number of repetitions (or with a counter);

      cycles with an unknown number of repetitions (cycles with precondition and cycles with postcondition).

In any loop there must be a variable that controls the exit from the loop, i.e. determines the number of repetitions of the loop.

The sequence of actions that must be performed on each cycle step(i.e. each time the cycle is repeated), is called body of the loop or working part of the cycle.

This article will look at examples of flowcharts that you may encounter in computer science textbooks and other literature. A flowchart is an algorithm by which any task assigned to the developer is solved. First you need to answer the question of what an algorithm is, how it is represented graphically, and most importantly, how to solve it, knowing certain parameters. It should be immediately noted that there are several types of algorithms.

What is an algorithm?

This word was introduced into use by the mathematician Muhammad al-Khwarizmi, who lived in the period 763-850. He is the person who created the rules for performing arithmetic operations (and there are only four of them). But GOST from 1974, which states that:

An algorithm is a precise prescription that defines a computational process. Moreover, there are several variables with given values ​​that lead the calculations to the desired result.

The algorithm allows you to clearly indicate to the performer to carry out a strict task in order to solve the task and get the result. Developing an algorithm is breaking down one large task into a certain sequence of steps. Moreover, the developer of the algorithm must know all the features and rules of its compilation.

Features of the algorithm

In total, eight features of the algorithm can be distinguished (regardless of its type):

  1. There is a function for entering initial data.
  2. There is an output of a certain result after the completion of the algorithm. It must be remembered that the algorithm is needed in order to achieve a certain goal, namely, to obtain a result that is directly related to the original data.
  3. The algorithm must have a discrete type structure. It should be presented in sequential steps. Moreover, each next step can begin only after the completion of the previous one.
  4. The algorithm must be unambiguous. Each step is clearly defined and does not allow arbitrary interpretation.
  5. The algorithm must be finite - it must be executed in a strictly defined number of steps.
  6. The algorithm must be correct - it must provide an exclusively correct solution to the problem.
  7. Generality (or mass character) - it must work with various initial data.
  8. The time given to solve the algorithm should be minimal. This determines the effectiveness of solving the problem.

And now, knowing what flowcharts of algorithms exist, we can begin to consider ways to write them. And there are not very many of them.

Verbal recording

This form is usually used when describing a procedure for a person: “Go there, I don’t know where. Bring something, I don’t know what.”

Of course, this is a comic form, but the essence is clear. As an example, we can cite, for example, the usual writing on bus windows: “In case of an accident, pull out the cord and push out the glass.”

Here a condition is clearly set under which two actions must be performed in strict sequence. But these are the simplest algorithms; there are also more complex ones. Sometimes formulas and special designations are used, but under the obligatory condition - the performer must understand everything.

It is possible to change the order of actions if you need to return, for example, to a previous operation or bypass some command under a certain condition. In this case, it is advisable to number the commands and be sure to indicate the command to which the transition occurs: “After finishing all the manipulations, repeat steps 3 to 5.”

Recording in graphical form

This recording involves flowchart elements. All elements are standardized, each team has a specific graphic entry. And a specific command must be written inside each of the blocks in ordinary language or mathematical formulas. All blocks must be connected by lines - they show the exact order of the commands being executed. Actually, this type of algorithm is more suitable for use in program code than a verbal one.

Recording in programming languages

If an algorithm is necessary for a problem to be solved by a program installed on a PC, then it must be written in special code. There are many programming languages ​​for this. And the algorithm in this case is called a program.

Block diagrams

A flowchart is a graphical representation of an algorithm. All commands and actions are represented by geometric shapes (blocks). Inside each figure is written all the information about the actions that need to be performed. Connections are shown as regular lines with arrows (if necessary).

For the design of flowcharts of algorithms, there is GOST 19.701-90. It describes the procedure and rules for creating them in graphical form, as well as the basic methods for solving them. This article provides the basic elements of flowcharts that are used in solving problems, for example, in computer science. Now let's look at the rules of construction.

Basic rules for drawing up a flowchart

We can highlight the following features that any block diagram should have:

  1. There must be two blocks - “Start” and “End”. And in a single copy.
  2. Communication lines must be drawn from the initial block to the final block.
  3. All blocks except the final one should have flow lines coming out of them.
  4. All blocks must be numbered: top to bottom, left to right. The serial number must be placed in the upper left corner, making a break in the style.
  5. All blocks must be connected to each other by lines. They are the ones who must determine the sequence in which actions are performed. If the flow moves from bottom to top or from right to left (in other words, in the reverse order), then arrows are necessarily drawn.
  6. Lines are divided into outgoing and incoming. It should be noted that one line is outgoing for one block, and incoming for another.
  7. The flow line only goes out from the initial block in the diagram, since it is the very first.
  8. But the final block only has an input. This is clearly shown in the block diagram examples provided in the article.
  9. To make block diagrams easier to read, incoming lines are shown at the top and outgoing lines at the bottom.
  10. Discontinuities in flow lines are acceptable. They must be marked with special connectors.
  11. To make the flowchart easier, it is allowed to write all the information in the comments.

Graphic elements of flowcharts for solving algorithms are presented in the table:

Linear type of algorithms

This is the simplest type, which consists of a certain sequence of actions; they do not depend on what data was entered initially. There are several commands that are executed once and only after the previous one has been completed. A linear block diagram looks like this:

Moreover, connections can go both from top to bottom and from left to right. Such a block diagram is used to write calculation algorithms using simple formulas that have no restrictions on the values ​​of the variables included in the calculation formulas. Linear algorithm is an integral part of complex calculation processes.

Branching Algorithms

Block diagrams built using such algorithms are more complex than linear ones. But the essence does not change. A branching algorithm is a process in which what happens next depends on how a condition is met and what solution is obtained. Each direction of action is a branch.

The diagrams depict blocks called “Solution”. It has two outputs, and a logical condition is written inside. The further movement according to the algorithm scheme depends on how it is performed. Branching algorithms can be divided into three groups:

  1. “Bypass” - in this case, one of the branches does not have operators. In other words, several actions on another branch are bypassed.
  2. “Branching” - each branch has a specific set of actions to perform.
  3. “Multiple choice” is a branch in which there are several branches and each contains a specific set of actions to be performed. Moreover, there is one peculiarity - the choice of direction directly depends on the given values ​​of the expressions included in the algorithm.

These are simple algorithms that can be solved very easily. Now let's move on to more complex ones.

Round robin algorithm

Everything here is extremely clear - a cyclic block diagram represents an algorithm in which similar calculations are repeated many times. By definition, a cycle is a specific sequence of actions performed repeatedly (more than once). And there are several types of cycles:

  1. In which the number of repetitions of actions is known (they are also called cycles with a counter).
  2. For which the number of repetitions is unknown - with a postcondition and a precondition.

Regardless of what type of loop is used to solve the algorithm, it must have a variable with which the output occurs. It determines the number of repetitions of the cycle. The working part (body) of the cycle is a certain sequence of actions that is performed at each step. Now let’s take a closer look at all the types of loops that can be encountered when creating algorithms and solving problems in computer science.

Loops with counters

The figure shows a simple block diagram in which there is a loop with a counter. This type of algorithm shows that the number of repetitions of a given cycle is known in advance. And this number is fixed. In this case, the variable that counts the number of steps (repetitions) is called a counter. Sometimes in textbooks you can find other definitions - a loop parameter, a control variable.

The block diagram very clearly illustrates how a counter loop works. Before you begin the first step, you need to assign an initial value to the counter - this can be any number, it depends on the specific algorithm. In the case when the final value is less than the counter value, a certain group of commands that make up the body of the loop will begin to be executed.

After the body is executed, the counter is changed by the counter step value, denoted by h. If the resulting value is less than the final value, the cycle will continue. And it will end only when the final value is less than the loop counter. Only in this case will the action that follows the cycle be executed.

Typically, flowchart notation uses a block called "Preparation". The counter is written in it, and then the following data is indicated: initial and final values, change step. In the block diagram these are the parameters I n, Ik and h, respectively. In the case when h=1, the step size is not recorded. In other cases, this is mandatory. A simple rule must be followed - the flow line must enter from the top. And the flow line that comes out from the bottom (or from the right, depending on the specific algorithm) should show the transition to the subsequent statement.

Now you have fully studied the description of the block diagram shown in the figure. You can move on to further study. When using a loop with a counter, certain conditions must be met:

  1. The body is not allowed to change (force) the counter value.
  2. It is prohibited to transfer control from outside to the body operator. In other words, you can only enter a cycle from its beginning.

Loops with precondition

This type of cycle is used in cases where the number of repetitions is unknown in advance. A precondition loop is a type of algorithm in which, immediately before the execution of the body begins, a condition is checked under which the transition to the next action is allowed. Pay attention to how the elements of the block diagram are depicted.

In the case when the condition is met (the statement is true), the transition to the beginning of the loop body occurs. It directly changes the value of at least one variable that affects the value of the stated condition. If you don't adhere to this rule, you'll end up with a loop. If, after the next check of the execution condition of the loop body, it turns out that it is false, then exit occurs.

In block diagrams of algorithms, it is allowed to check not the truth, but the falsity of the initial condition. In this case, the loop will exit only if the condition value turns out to be true. Both options are correct; their use depends on which one is more convenient to use to solve a particular problem. This type of loop has one feature - the body may not be executed if the condition is false or true (depending on the option that is used to solve the algorithm).

Below is a flowchart that describes all these steps:

What is a loop with a postcondition?

If you look closely, this type of cycle is somewhat similar to the previous one. We will now try to construct a block diagram describing this cycle ourselves. The peculiarity is that the number of repetitions is unknown in advance. And the condition is set after the exit from the body has occurred. From this we can see that the body, regardless of the decision, will be executed at least once. For clarity, take a look at the block diagram describing the execution of the condition and operators:

There is nothing complicated in constructing algorithms with loops; you only need to understand them once. Now let's move on to more complex structures.

Complex Loops

Complex ones are those structures that contain one or more simple loops inside them. Sometimes they are called nested. Moreover, those constructions that cover other cycles are called “external”. And those that are included in the design of external ones are internal. When each step of the outer loop is executed, the inner loop is completely scrolled, as shown in the figure:

That's all, you have reviewed the main features of constructing flowcharts for solving algorithms, you know the principles and rules. Now we can look at specific examples of flowcharts from life. For example, in psychology such constructions are used to help a person solve a question:

Or an example from biology to solve the problem:

Solving problems with flowcharts

Now let's look at examples of problems with flowcharts that can be found in computer science textbooks. For example, a block diagram is given according to which some algorithm is solved:

In this case, the user independently enters the values ​​of the variables. Let's say x=16 and y=2. The execution process is as follows:

  1. The x and y values ​​are entered.
  2. The transformation operation is performed: x=√16=4.
  3. The condition is met: y=y 2 =4.
  4. The calculation is made: x=(x+1)=(4+1)=5.
  5. Next, the following variable is calculated: y=(y+x)=(5+4)=9.
  6. The solution is output: y=9.

This example of a computer science flowchart clearly shows how the algorithm is solved. It is necessary to pay attention to the fact that the values ​​of x and y are specified at the initial stage and they can be anything.

Schemethis is an abstraction of a process or system that clearly displays the most significant parts. Schemes have been widely used from ancient times to the present day - drawings of ancient pyramids, maps of lands, electrical circuit diagrams. Obviously, the ancient sailors wanted to exchange maps and therefore developed a unified system of notations and rules for their implementation. Similar agreements have been developed for the depiction of algorithmic diagrams and are enshrined in GOST and international standards.

Operates on the territory of the Russian Federation unified system of program documentation (USPD), of which the State Standard is a part - GOST 19.701-90 “Algorithm diagrams for programs, data and systems”. Despite the fact that the notations described in the standard can be used to depict system resource diagrams, program interaction diagrams, etc., this article only describes the development of program algorithm diagrams.

The GOST under consideration almost fully complies with the international standard ISO 5807:1985.

Algorithm flowchart elements

A block diagram is a set of symbols corresponding to the stages of the algorithm and the lines connecting them. Dotted line used to connect a symbol with a comment. solid line reflects control dependencies between symbols and can be provided with an arrow. The arrow may not be indicated when the arc is directed from left to right and from top to bottom. According to clause 4.2.4, the lines should approach the symbol from the left, or from above, and come from below, or from the right.

There are other types of lines used, for example, to depict block diagrams of parallel algorithms, but they, as well as a number of specific symbols, are not considered in the current article. Only basic symbols are considered, which are always enough for students.

Terminator for the start and end of the function

Every function begins and ends with a terminator. The type of the function's return value and arguments is usually specified in the comments of the terminator block.

Data input and output operations

GOST defines many input/output symbols, for example output to magnetic tapes, displays, etc. If the data source is not critical, the parallelogram symbol is usually used. I/O details can be specified in the comments.

Performing operations on data

An operations block usually contains one or more (GOST does not prohibit) assignment operations that do not require calling external functions.

Block illustrating the branching of the algorithm

The diamond-shaped block has one input and several signed outputs. If a block has 2 outputs (corresponds to a branching operator), the result of the comparison is signed to them - “yes/no”. If more lines come out of the block (selection operator), the name of the variable is written inside it, and the values ​​of this variable are written on the outgoing arcs.

Calling an external procedure

Calls to external procedures and functions are placed in a rectangle with additional vertical lines.

Start and end of the cycle

The start and end symbols for a loop contain a name and a condition. The condition may not be present in one of the symbols of the pair. The location of the condition determines the type of operator corresponding to the symbols in the high-level language - an operator with a precondition (while) or a postcondition (do ... while).

Data preparation

The “data preparation” symbol in any form (there are no explanations or examples in GOST) specifies the input values. Typically used to define counter cycles.

Connector

If the flowchart does not fit on a sheet, a connector symbol is used to reflect the transition of control flow between sheets. The symbol can be used on one sheet if for some reason it is not convenient to draw a line.

A comment

A comment can be connected to either one block or a group. A group of blocks is highlighted on the diagram with a dotted line.

Block diagram examples

As examples, block diagrams of very simple sorting algorithms are constructed, with emphasis on various implementations of loops, because Students make the greatest number of mistakes in this part.

Insertion sort

Array in the algorithm insertion sort divided into sorted and not yet processed parts. Initially, the sorted part consists of one element, and gradually increases.

At each step of the algorithm, the first element of the raw part of the array is selected and inserted into the sorted part so that the required order of elements is preserved. The insertion can be performed either at the end of the array or in the middle. When inserting into the middle, you must move all elements located “to the right” of the insertion position one element to the right. The algorithm uses two loops - in the first, elements of the raw part are selected, and in the second, insertion is carried out.


Flowchart of Insertion Sort Algorithm

The block diagram below uses a branch symbol to organize the loop. In the main loop (i< n) Iterates through the elements of the raw part of the array. If all elements are processed, the algorithm terminates; otherwise, a position for insertion is searched i-that element. The searched position will be stored in the variable j as a result of the inner loop, which shifts elements until an element is found whose value is less i-that.

On block diagram shows how the transition symbol can be used - it can be used not only to connect parts of circuits located on different sheets, but also to reduce the number of lines. In some cases, this allows you to avoid crossing lines and makes the algorithm easier to understand.

Bubble sort

Bubble sort, as well as insertion sort, uses two loops. In a nested loop, a pairwise comparison of elements is performed and, if their order is violated, a rearrangement is performed. As a result of executing one iteration of the inner loop, the maximum element is guaranteed to be shifted to the end of the array. The outer loop runs until the entire array is sorted.


Flowchart of Bubble Sort Algorithm

The block diagram shows the use of the start and end loop symbols. The outer loop condition (A) is checked at the end ( with postcondition), it works as long as the variable hasSwapped has the meaning true. The inner loop uses precondition to iterate through pairs of compared elements. If the elements are in the wrong order, they are rearranged by calling external procedure (swap). In order to understand the purpose of the external procedure and the order of its arguments, it is necessary to write comments. If the function returns a value, a comment can be written to the end terminator character.

Sorting by selection

IN selection sorting the array is divided into sorted and raw parts. Initially, the sorted part is empty, but gradually it increases. The algorithm searches for the minimum element of the unprocessed part and swaps it with the first element of the same part, after which it is considered that the first element has been processed (the sorted part is increased).


Selection sort flowchart

The block diagram shows an example of using the “preparation” block, and also shows that in some cases it is possible to describe the algorithm in a more “enlarged” way (without going into details). Implementation details have nothing to do with selection sort finding the index of the minimum array element, so they can be described by an external procedure call symbol. If there is no block diagram of the external procedure algorithm, it would not hurt to write a comment to the call symbol; an exception may be functions with meaningful names like swap, sort, … .

You can find it on the blog other block diagram examples:

Some students traditionally try to draw flowcharts in Microsoft Word, but it turns out to be difficult and inconvenient. For example, in MS Word there is no standard block for the start and end terminator of the algorithm (a rounded rectangle, not an oval). The most convenient, in my opinion, are the utilities MS Visio And yEd, both of them allow you to do much more than build flowcharts (for example, draw UML diagrams), but the first is paid and only works under Windows the second is free and cross-platform. All flowcharts in this article are made using yEd.

Development of a block diagram of an algorithm for solving a problem

Goal of the work: study of a graphical method of describing an algorithm for solving a problem.

Job Objectives:

    become familiar with the main ways of presenting algorithms;

    master the graphical method of describing algorithms.

1.1. Work order

    Study the theoretical information on the topic of this section (section 1.2)

    Read the problem statement (section 1.3). The task option corresponds to your number on the group list.

    Develop a block diagram of an algorithm for solving the problem.

    Answer the security questions.

    Prepare a report on the implementation of practical work, which should contain:

    title page;

    purpose of practical work;

    problem statement;

    block diagram of the algorithm for solving the problem;

    answers to security questions;

    conclusions from practical work.

1.2. General information

One of the most labor-intensive stages of solving a problem on a computer is developing an algorithm.

Under algorithm is understood as an exact prescription that defines the computational process leading from varying initial data to the desired result.

The main characteristic properties of the algorithm are:

    determinacy (certainty) – given the initial data, the unambiguity of the desired result is ensured;

    mass character – suitability for tasks of a given type with initial data belonging to a given subset;

    efficiency - the implemented computational process is performed in a finite number of stages with the output of a meaningful result;

    discreteness – the ability to split the algorithm into separate stages, the implementation of which is beyond doubt.

The following are distinguished: types of computing processes:

    Linear computational process.

To obtain the result, it is necessary to perform certain operations in a certain sequence.

    Branched computing process.

The specific sequence of operations depends on the values ​​of one or more parameters. For example, if the discriminant of a quadratic equation is not negative, then the equation has two roots, and if it is negative, then there are no real roots.

    Cyclic computing process

To obtain a result, a certain sequence of actions must be performed several times. For example, in order to obtain a table of function values ​​at a given interval of changing the argument with a given step, it is necessary to determine the next value of the argument an appropriate number of times and calculate the function value for it.

In turn, there are also several types of cyclic computing process, namely:

    WITH even cycles (cycles with a given number of repetitions) – These are cyclic processes for which the number of repetitions is known.

    Iterative loops are cyclic processes that end when certain conditions are met or violated.

    P search cycles – These are cyclical processes from which there are two possible exits:

Exit when the process is completed;

Early exit under any additional condition.

Based on the type of computational process implemented by the algorithm, there are:

Linear structure algorithms;

Branched structure algorithms;

Algorithms for cyclic structure.

Algorithms for solving practical problems usually have a combined structure, that is, they include all three types of computational processes.

Visual means of describing algorithms include the following main ways of representing them:

Verbal (natural language recordings);

Structural-stylized (records in algorithmic language and pseudocode);

Graphic (image of diagrams and graphic symbols);

Programming (texts in programming languages).

Verbal method description of the algorithm is a description of successive numbered stages of data processing and is given in any form in natural language.

Example 1.1.

Algorithm for adding two numbers (a and b).

    Ask what the number a is equal to.

    Ask what the number b is equal to.

    Add a and b, assign the result to c.

    Report result c.

The advantage of this method is the simplicity of the description, but the disadvantages include the fact that this approach is verbose and does not have strict formalization, therefore it allows for ambiguity in the interpretation of individual instructions, due to which the verbal method of presenting the algorithm is not widespread.

To strictly specify various data structures and algorithms for their processing, it is necessary to have such a system of formal notations and rules so that the meaning of any used prescription is interpreted accurately and unambiguously. The corresponding systems of rules are called description languages. These include algorithmic languages ​​(pseudocodes), flowcharts, and programming languages.

Structural stylized way algorithm description is based on recording algorithms in a formalized representation of instructions, specified by using a limited set of standard syntactic structures, often called pseudocodes.

The advantage of pseudocodes is their proximity to programming languages, and the disadvantages, in turn, are the difficulty of mastering and the impossibility of directly entering the algorithm for solution on a computer, i.e. the need for translation into a programming language.

Graphic method description of the algorithm assumes that to describe the structure of the algorithm, a set of graphic images (blocks) connected by control transmission lines is used. This image is called block diagram method.

Block diagram An algorithm is a graphical representation of the progress of solving a problem. A flowchart consists of blocks connected by lines, and the blocks are depicted as geometric shapes called symbols. Inside the symbols, instructions are written about the functions performed by the block - formulas, text, logical expressions. The type of symbols and rules for executing block diagrams are standardized - GOST 19.701-90 contains a list of symbols, their names, displayed functions, shapes and sizes, as well as rules for executing diagrams. When developing an algorithm, each action is designated by a corresponding block, showing their sequence with lines with arrows at the end. The names, designations and purpose of block diagram elements are shown in Fig. 1.1.

Figure 1.1 – Main blocks

It is worth mentioning some basic rules for executing flowcharts that should be followed when describing algorithms graphically. The beginning of the algorithms is marked by the “Terminator” symbol, from which one line emerges. The word “Start” (“Start”) is written in it. The end of the algorithm is marked with the same symbol, in which the word “Stop” (“End”) is written. In this case, this symbol does not have a single output line, but one or more lines can be connected to it. The Process symbol can have one or more input lines and only one output line. Several instructions can be written inside a symbol - in this case they are carried out in the order they were written. The presentation of individual operations is quite free. To indicate calculations, you can use mathematical expressions, to send data - arrows, for other actions - explanations in natural language, for example, A: = X + 4; i: = i + 1, ––> B.

The flow lines should be parallel to the sides of the sheet. The main directions of flow lines - from top to bottom and from left to right - are not indicated by an arrow. In other cases, an arrow is placed at the end of the flow line, and a dot is placed where the lines meet. If the block diagram does not fit on one sheet, connectors are used. When moving to another sheet or receiving control from another sheet, the sheet number is indicated in the comment, for example, “from sheet 3” “to sheet 1”.

To write an algorithm of any complexity it is enough three basic structures:

    following - denotes the sequential execution of actions (Fig. 1.2, a);

    branching - corresponds to the choice of one of two options for action (Fig. 1.2, b);

    cycle-bye - determines the repetition of actions until a condition is violated, the fulfillment of which is checked at the beginning of the cycle (Fig. 1.2, c).

Figure 1.2 – Basic algorithmic structures

In addition, when describing algorithms, we use additional algorithmic structures, derived from the basic ones, each of which can be implemented through basic structures:

    choice - choosing one option from several depending on the value of a certain quantity (Fig. 1.3, a, b);

    cycle-to- repeating some actions until a given condition is met, which is checked after performing the actions in the cycle (Fig. 1.3, c, d);

    loop with a given number of repetitions (counting cycle) repeating some actions a specified number of times (Fig. 1.3, e, f).

Figure 1.3 – Implementation of additional algorithmic structures

through basic structures

Let's look at examples of graphical descriptions of algorithms of various types: linear, branching, cyclic and combined (Fig. 1.4 - 1.7).

Example 1.2. Linear algorithm.

Algorithm for calculating the value of the expression K=3b+6a (Fig. 1.4).

Figure 1.4 – Example of a linear algorithm block diagram

Example 1.3. Branching algorithm.

An algorithm that determines whether the graph of the function y=3x+4 will pass through the point with coordinates x1,y1 (Fig. 1.5).

Figure 1.5 – Example of a block diagram of a branching algorithm

Example 1.4. Cyclic algorithm.

Algorithm that determines the factorial of a natural number n (Fig. 1.6):

n! = 1*2*3*….*(n-1)* n

5!=1*2*3*4*5=120

Figure 1.6 – Example of a block diagram of a cyclic algorithm

Example 1.5. Combined algorithm.

It is necessary to determine the greatest common divisor of two natural numbers A and B.

To solve the problem, we use the Euclidean algorithm, which consists of sequentially replacing the larger number with the difference of the larger and smaller numbers until the numbers become equal. Let's look at this algorithm using two examples.

Example (a): A=225, B=125. Applying the Euclidean algorithm, we obtain for A and B the greatest common divisor equal to 25.

Example (b): A=13, B=4. In this case, the greatest common divisor of A and B is 1.

B

50-25=25

A block diagram of the Euclidean algorithm for finding the greatest common divisor of two natural numbers is shown in Fig. 1.7.

Figure 1.7 – Example of a block diagram of a combined algorithm

The flowchart of an algorithm displays in detail all the features of the developed algorithm, but sometimes such a high level of detail does not allow the essence of the algorithm to be highlighted. In these cases, the algorithm is described using pseudocode. Pseudocode is based on the same basic structures as the block diagrams of the algorithm (Table 1.1).

Example 1.6. Description of the Euclidean algorithm in pseudocode.

Euclid's algorithm:

Enter A, B

cycle-bye A ≠ B

If A > B

That A:= A - B

otherwise B:= B - A

all - if

all-cycle

Output A

End of the algorithm.

Table 1.1 – Example of pseudocode for writing basic algorithmic structures

Structure

Pseudocode

Structure

Pseudocode

Following

Choice

All-choice

Branching

If

given

number of repetitions

For =

otherwise

All - if

All-cycle

Cycle-bye

Cycle-bye

Fulfill

All-cycle

1.3. Problems for drawing up flowcharts of algorithms

    Given an integer m>1.

Find the smallest integer k such that 4 k >m.

Calculate product

    An integer n is given.

Get the smallest number of the form 2 r that exceeds n (r is a natural number).

    Given integers n, k (n  k  0).

Calculate.

    Given a natural number n and a real number a.

Calculate the product.

    Given a natural number n.

Calculate Sum .

    Given a real number x and a natural number n.

Calculate without using exponentiation.

    Given a natural number n.

Calculate the amount:

    Given real numbers x and a, natural number n.

Calculate:

Calculate:

    Given natural numbers n, m.

    Get the sum of the last m digits of number n.

    Given a natural number n.

Calculate the amount:

Let n be a natural number.

    Calculate the amount.

    Control questions

    Define an algorithm.

    List the main properties of algorithms and reveal their essence.

    How are algorithms divided by the type of computational process being implemented?

    What ways of describing algorithms do you know?

    What is meant by a graphical way of describing algorithms? What is the advantage of this method over a verbal description of the algorithm?-Coursework >> Computer Science Weights of the edges of the remaining tree. 2.4 What is the advantage of this method over a verbal description of the algorithm?-Coursework >> Computer Science Block scheme Figure 7 – algorithm solutions tasks

  1. 2.5 Rationale for choosing the Turbo... programming language, an integrated environment that greatly speeds up the process development

    programs. This software product has passed...

    Algorithms scheme and programming basics Practical work >> Computer science, programming Programming various tasks What is the advantage of this method over a verbal description of the algorithm?-Coursework >> Computer Science on electronic computers; science dealing with Block development methods... . scheme ...

  2. given linear shown in Figure 4. Example 1. Calculate at x=2.3 In general, algorithm Construction block

    schemes

    algorithms . High-level algorithmic languages Abstract >> Computer Science Practical work >> Computer science, programming. Approach to decision What is the advantage of this method over a verbal description of the algorithm?-delivered Construction Tasks implemented in three different programming languages. scheme Figure 7 – scheme solutions, program listings... time.

  3. Algorithm

    schemes

    ... : turns out to be more effective if you use the step-by-step method shown in Figure 4. Example 1. Calculate at x=2.3 In general, delivered Block scheme Figure 7 –, the point... blocks delivered Block scheme Figure 7 –. What is the advantage of this method over a verbal description of the algorithm? System and software Figure 7 – Development

for monitoring the knowledge of FPK students. DescriptionFFffuvvya

1 ... – enter a name (designation)

, enter... 8.2. Algorithm flowcharts refers to a graphical representation of the definition, analysis, or method of solving a problem. Diagrams can be used to depict both static and dynamic aspects of a system. The symbols given in the state standard can be used in the following types of circuits :

Data schemas – determine the sequence of data processing and their media;

Program diagrams - display the sequence of operations in the program (in fact, these are flowcharts of algorithms in the traditional sense);

System operation diagrams – display the management of operations and data flows in the system;

Program interaction diagrams – display the path of activation of programs (modules) and their interaction with the corresponding data;

System resource diagrams - display the configuration of data blocks and processing blocks.

As can be seen from the above types of diagrams, they can be used not only for modeling the behavioral aspect, but also for functional, information and component design problems.

When constructing a behavioral model of the system, the basic principles of the structural approach are used - the principles of decomposition and hierarchical ordering. A behavioral model is a set of interconnected diagrams (diagrams) with different levels of detail, and with each new level of detail the system acquires more and more complete outlines.

The diagrams may include the following: elements of graphic notation :

Data symbols - indicate the presence of data, the type of media, or the method of input/output of data;

Process symbols - indicate the operations that should be performed on the data;

Line symbols - indicate data flows between processes and/or storage media, as well as control flows between processes;

Special characters – used to make diagrams easier to write and read.

In addition to dividing according to semantic content, each category of symbols (except special ones) is divided into basic and specific symbols. Basic symbol used when the exact type of process or storage medium is unknown or there is no need to describe the actual storage medium (process). Specific character used when the exact type of process or storage medium is known and this needs to be shown on the diagram. The following table shows the elements of graphical flowchart notation.

Table 8.1. Symbols on block diagrams

No. Symbol Name Notes
1. DATA SYMBOLS
Basic
1.1 Data Data whose carrier is not defined
1.2 Storage device (memory) Data stored in a form suitable for automatic processing, medium not defined
Specific
1.3 RAM Data stored in RAM (random access memory)
1.4 Serial memory Data stored on magnetic tape (magnetic tape, tape cassette)
1.5 Direct access memory Data stored on hard or floppy disks, CDs, DVDs, ZIPs, etc.
1.6 Document Data not presented in computer form (on paper, on films, etc.)
1.7 Manual input Data entered manually using a keyboard, mouse, pen, etc.
1.8 Map Data on punched cards, magnetic cards, readable tag cards, etc.
1.9 Paper tape Data on paper tape
1.10 Display Data displayed on the monitor screen, signal indicators, etc.
2. PROCESS SYMBOLS
Basic
2.1 Process Elementary (atomic) data processing operation (for example, n:=n+1)
Specific
2.2 Predefined process (procedure) A process consisting of operations described elsewhere (on another diagram)
2.3 Manual operation Manual operation
2.4 Preparation Preparatory operations performed to modify subsequent operations (loop with parameter)
2.5 Solution An operation with one input and several alternative outputs, one of which is activated after testing the condition written inside the symbol (If-Then-Else or Case statements)
2.6 Parallel activities Parallel execution of two or more operations
2.7 Cycle boundaries The beginning and end of the cycle. Features of the loop (initialization, increment, condition) are recorded at the beginning or end, depending on where it is checked (cycles with pre- or postcondition)
3. LINE SYMBOLS
Basic
3.1 Line Data or control flow
Specific
3.2 Link Data transmission via communication channel
3.3 Dotted line An alternative connection between two or more symbols or for outlining a commented section of the diagram
4. SPECIAL CHARACTERS
4.1 GOST Connector Used to break lines and continue them elsewhere.
Typically used to indicate interconnected parts of a diagram on different sheets. The connection number is written inside the connector
ISO
4.2 Terminator Exit to the external environment or input from the external environment (the beginning and end of a data processing process [in this case, “beginning” or “end” is written inside], the source or destination of data, the beginning and end of a predefined process)
4.3 Recipient sender Functionally similar to the "Terminator" symbol
4.4