The block diagram describes. Basic blocks for drawing up algorithm diagrams. Flowcharts are used in sales

2.1 Development of the algorithm.

Algorithm- This

a. description of the sequence of actions to solve a problem or achieve a goal;

b. rules for performing basic data processing operations;

c. description of calculations using mathematical formulas.

Before starting to develop an algorithm, it is necessary to clearly understand the task: what is required to be obtained as a result, what initial data is needed and what is available, what restrictions exist on this data. Next, you need to write down what actions need to be taken to obtain the required result from the initial data.

In practice, the most common forms of presenting algorithms are:

Verbal (recordings in natural language);

Graphic (images from graphic symbols);

Pseudocodes (semi-formalized descriptions of algorithms in a conditional algorithmic language, including both elements of a programming language and natural language phrases, generally accepted mathematical notations, etc.);

Software (texts in programming languages).

The verbal way of writing algorithms is a description of the successive stages of data processing. The algorithm is specified in a free form in natural language.

Example. Write down an algorithm for finding the greatest common divisor (GCD) of two natural numbers.

The algorithm could be as follows:

1. set two numbers;

2. if the numbers are equal, then take any of them as the answer and stop, otherwise continue executing the algorithm;

3. determine the largest of the numbers;

4. replace the larger number with the difference between the larger and smaller numbers;

5. repeat the algorithm from step 2.

The described algorithm is applicable to any natural numbers and should lead to a solution to the problem. Convince yourself of this by using this algorithm to determine the greatest common divisor of the numbers 125 and 75.

The verbal method is not widespread for the following reasons:

Such descriptions are not strictly formalizable;

Suffer from wordiness of notes;

There is room for ambiguity in the interpretation of individual regulations.

The graphical way of presenting algorithms is more compact and visual compared to the verbal one.

When presented graphically, the algorithm is depicted as a sequence of interconnected functional blocks, each of which corresponds to the execution of one or more actions.

This graphical representation is called a flowchart or flowchart.

Pseudocode is a system of notations and rules designed to uniformly write algorithms.

It occupies an intermediate place between natural and formal languages.

On the one hand, it is close to ordinary natural language, so algorithms can be written and read in it like regular text. On the other hand, pseudocode uses some formal constructs and mathematical symbolism, which brings the algorithm notation closer to the generally accepted mathematical notation.

In pseudocode, strict syntactic rules for writing commands inherent in formal languages ​​are not adopted, which makes it easier to write the algorithm at the design stage and makes it possible to use a wider set of commands designed for an abstract executor. However, pseudocode usually contains some constructs that are inherent in formal languages, which makes it easier to move from writing in pseudocode to writing an algorithm in a formal language. In particular, in pseudocode, as well as in formal languages, there are function words, the meaning of which is determined once and for all. There is no single or formal definition of pseudocode, so various pseudocodes are possible, differing in the set of function words and basic (basic) constructions.

2.2 Block diagram.

A flowchart is a graphical representation of an algorithm in which it is depicted as a sequence of interconnected functional blocks, each of which corresponds to the execution of one or more actions.

In the flowchart, each type of action (entering initial data, calculating the values ​​of expressions, checking conditions, controlling the repetition of actions, completing processing, etc.) corresponds to a geometric figure represented as a block symbol. Block symbols are connected by transition lines that determine the order in which actions are performed.

Here are the most commonly used symbols.

Symbol name Designation and example of filling Explanation
Process Computational action or sequence of actions
Solution Checking conditions
Modification Start of the cycle
Predefined process Calculations by subroutine, standard subroutine
Input Output I/O in General
Start-stop Beginning, end of the algorithm, entry and exit to the subroutine
Document Printing results

The "process" block is used to denote an action or sequence of actions that changes the meaning, form of presentation or placement of data. To improve the clarity of the diagram, several individual processing blocks can be combined into one block. The presentation of individual operations is quite free.

The "decision" block is used to indicate conditional control transitions. Each "solution" block must identify the question, condition, or comparison that it defines.

The "modification" block is used to organize cyclic structures. (The word modification means modification, transformation). A cycle parameter is written inside the block, for which its initial value, boundary condition and step of changing the parameter value are indicated for each repetition.

The "predefined process" block is used to indicate calls to auxiliary algorithms that exist autonomously in the form of some independent modules, and for calls to library routines.

Example. Draw up a block diagram of an algorithm for determining the heights ha, hb, hc of a triangle with sides a, b, c, if



Where p = (a + b + c) / 2.
Solution. Let us introduce the notation then h a = t/a, h b = t/b, h c = t/c. The flowchart must contain start, input a, b, c, calculation p, t, h a, h b, h c , output the results and stop.

2.3 Algorithm structures.

Algorithms can be thought of as certain structures consisting of individual basic (i.e. basic) elements. Naturally, with this approach to algorithms, the study of the basic principles of their design should begin with the study of these basic elements

The logical structure of any algorithm can be represented by a combination of three basic structures: following, branching, and looping.

A characteristic feature of basic structures is the presence of one input and one output.

1. Basic structure follows. Formed from a sequence of actions following one after another:

2. Basic branching structure. Provides, depending on the result of checking the condition (yes or no), the choice of one of the alternative ways of operating the algorithm. Each path leads to a common output, so the algorithm will continue to run no matter which path is chosen.

Structure branching exists in four main variants:

If-then-else;

The choice is different.

1) if then if condition then actions end if 2) if-else if condition then actions 1 otherwise actions 2 end if 3) choice choice with condition 1: actions 1 with condition 2: actions 2. . . . . . . . . . . . under condition N: actions N end of choice

4) choice - otherwise choice under condition 1: action 1 under condition 2: action 2. . . . . . . . . . . .

under condition N: actions N otherwise actions N+1 end of choice

Example. Create a block diagram of the algorithm for calculating the function

The basic structure is a cycle. Provides repeated execution of a certain set of actions, which is called the body of the loop. The cycle structure exists in three main versions:.

Loop type

The basic structure is a cycle. Provides repeated execution of a certain set of actions, which is called the body of the loop. For.

Instructs to execute the loop body for all values ​​of a certain variable (loop parameter) in a given range.

The basic structure is a cycle. Provides repeated execution of a certain set of actions, which is called the body of the loop. Bye.

Orders the body of the loop to be executed as long as the condition written after the word while is satisfied.

do while

Orders the body of the loop to be executed as long as the condition written after the word while is met. The condition is checked after the loop body is executed. Note that loops for and while are also called loops with pre-checking the condition, and loops to do - while - loops with post-checking the condition. In other words, the bodies of the for and while loops may not be executed even once if the loop ending condition is not initially true. Do the body of the loop until it is executed at least once, even if the condition for ending the loop is not initially true. Cycle for i from i1 to i2 step i3 cycle body (sequence of actions) end of cycle

loop while condition loop body (sequence of actions) end of loop

cycle do loop body (sequence of actions) until condition end of loop

with a given accuracy (for a given alternating power series, the required accuracy will be achieved when the next term becomes smaller in absolute value).

Calculating sums is a typical cyclic task. The peculiarity of our specific problem is that the number of terms (and, consequently, the number of repetitions of the loop body) is unknown in advance. Therefore, the loop must end when the required accuracy is achieved.

When compiling an algorithm, you need to take into account that the signs of the terms alternate and the power of the number x in the numerators of the terms increases.

we will end up with a very inefficient algorithm that requires a large number of operations. It is much better to organize the calculations as follows: if you designate the numerator of any term by the letter p, then the numerator of the next term will be equal to -р*х (the minus sign ensures the alternation of the signs of the terms), and the term itself will be m

will be equal to p/i, where i is the number of the term.

An algorithm that includes an iterative loop is called an iterative algorithm. Iterative algorithms are used in the implementation of iterative numerical methods. In iterative algorithms, it is necessary to ensure that the condition for exiting the cycle is achieved (convergence of the iterative process). Otherwise, the algorithm will loop, i.e. the main property of the algorithm - effectiveness - will not be fulfilled.

Nested loops.

There may be cases when it is necessary to repeat a certain sequence of statements inside the body of a loop, that is, to organize an inner loop. This structure is called a loop within a loop or nested loops. The nesting depth of loops (that is, the number of loops nested within each other) can be different.

When using such a structure, to save computer time, it is necessary to move all statements that do not depend on the parameter of the inner loop from the inner loop to the outer one.

Example nested loops for. Calculate the sum of the elements of the given matrix A(5,3).

Example nested loops for now. Calculate the product of those elements of the given matrix A(10,10) that are located at the intersection of even rows and even columns.

Introduction

Drawing up a block diagram that meets all GOST requirements is a slow and painstaking process. If you are having trouble designing a flowchart or are confused about which flowchart element need to be used in a specific place, then sign up for a tutoring lesson with me. In a private lesson, you can ask me absolutely any question regarding the visualization of a flowchart.

Key Elements of a Flowchart

Basic elements used in block diagram design

Item name

Graphic display

Function

Terminator or start-end block

Indicates the beginning or end of a program. This block separates the boundaries of the program from the external environment. As a rule, the phrases “Beginning”, “Start” or “End”, “Finish” are entered into this element.

Command, process, action block

This block is responsible for performing one or more operations. As a rule, at this time flowchart element enter commands that change data and variable values. For example, an arithmetic operation on two variables will be written in this block.

Logical condition block

Let me remind you that the result of a logical condition is always one of two predefined values: true or false. A logical condition is written inside this diamond element, and alternative branches of the solution emerge from the vertices of the diamond. It is imperative to sign the branches with the words “Yes” and “No” so as not to mislead the reader of the flowchart.

Predefined process

If your program provides for the presence of subroutines: procedures or functions, then the call to the subroutine is written inside this element.

Data input/output block

Responsible for the form of data submission, for example, for user input from a keyboard or for outputting data to a personal computer monitor. It is very important to understand that this flowchart element does not identify the data carrier.

Loop block with counter

Responsible for executing cyclic commands in the for loop. A loop header with a counter is written inside the element, and the operations of the loop body are located below the element. With each iteration of the loop, the program returns to the loop head using the left arrow. The for loop is exited using the right arrow.

Paired block for loops with pre- and postconditions

This block consists of two parts. The operations of the loop body are placed between them. The loop header and loop counter changes are written inside the top or bottom block, depending on the loop architecture.

Used to break the communication line between flowchart elements. For example, if you are building a large-scale flowchart on an A4 sheet, and it does not fit on one sheet, then you will have to transfer the flowchart to a second sheet. In this case, you will need to use this connector. As a rule, a unique identifier, which is a natural number, is indicated inside the circle.

We looked at eight basic flowchart elements, using which you can easily implement absolutely any block diagram, based on the requirements or university program.

If you want to deepen your knowledge in the field of building flowcharts or have not fully understood any flowchart element, then sign up for a private lesson with me. In this lesson, we will analyze all your questions in detail, and also draw up a colossal number of flowcharts of varying degrees of complexity.

When considering a cyclic algorithm, several concepts should be highlighted.

Loop body is a set of instructions designed to be executed repeatedly.

Iteration is a single execution of the loop body.

Loop variable is a quantity that changes at each iteration of the loop.

Each loop must contain the following required elements:

  1. initial setting of the loop variable,
  2. checking the condition,
  3. execution of the loop body,
  4. changing the loop variable.

There are two types of cycles - with a precondition and with a postcondition. IN loop with precondition The loop entry condition is first checked, and then the body of the loop is executed if the condition is true. A cycle with a precondition is shown in Fig. 2.9. A precondition loop can also be specified using a counter. This is convenient in cases where the number of iterations is known exactly. In general, a block diagram that implements a loop with a precondition is presented below. First, the initial value of the loop variable is set, then the condition for entering the loop, the body of the loop, and the change in the loop variable. The loop is exited when the loop entry condition is checked when it is not satisfied, i.e. condition is false. A loop with a precondition may never be executed if the first time the loop entry condition is checked, it turns out to be false.


Rice. 2.9.

IN loop with postcondition First the body of the loop is executed and then the condition is checked. The cyclic algorithm with a postcondition is shown in Fig. 2.10.


Rice. 2.10.

If the condition is true, then the iteration is repeated, but if it is false, then the loop is exited. Unlike a loop with a precondition, any loop with a postcondition will always be executed at least once.

Note. As can be seen from the presented block diagrams for loops with precondition and postcondition, the condition is written inside the condition block (diamond shape), as in the branching algorithm. The fundamental difference between branching and cyclic algorithms in a graphical implementation is that in a cyclic algorithm there must be an arrow going up. It is this arrow that ensures the body of the cycle is repeated multiple times.

Let us give the simplest examples corresponding to the cyclic algorithm.

Example 7. Vasya calls Petya, but Petya’s line may be busy. Draw up a flowchart of Vasya’s actions in this case.

Solution. When the telephone line is busy, you need to dial the number again and again until Petya finishes the previous conversation and the telephone line is free again. The block diagram is shown in Fig. 2.11.


Rice. 2.11.

Here the body of the loop consists of one action “Dial Petya’s number”, because This is the action that should be repeated while the line is busy. An iteration of a cycle means another attempt to reach Petya. There is no loop variable as such here, because the situation is taken from life. The loop exits at the moment when the condition “Petya is busy” becomes false, i.e. The telephone line is free - indeed, there is no need to dial Petya’s number anymore. In this example, a loop with a postcondition is used, because First you need to dial Petya’s number, because otherwise we cannot answer the question whether Petya’s line is busy.

Example 8. A student needs to buy a textbook. Create a flowchart describing what a student should do if the textbook is not available in a number of stores.

Solution. The student’s actions in this example are obvious: when he comes to the first and any subsequent stores, two options are possible - the textbook is available or the textbook is not on sale. If the textbook is not on sale, then the student should go to another bookstore and ask for this textbook, etc. until the textbook is purchased, because The student's ultimate goal is to buy a textbook. We will use a loop with a precondition, because First you need to find a store that stocks this textbook. The loop will run as long as the condition “There is no textbook in this store” is true, and the loop will exit when the condition becomes false, i.e. when the student comes to the store that has this textbook. Indeed, in this case, the student will buy the textbook he needs and will no longer look for bookstores. The result of the block diagram is shown in Fig. 2.12.


Rice. 2.12.

Here the body of the loop consists of a single action "Find another bookstore". There is no explicit loop variable, but you can mean the number of the store to which the student came again. Like any other loop with a precondition, this loop may never be executed (have no iterations) if the required textbook is in the first store.

Note. If you add a condition for selecting a textbook in hard or soft cover to this task, as in Example 5, then it will appear after exiting the loop. This condition will not affect the implementation of the cyclic algorithm.

Example 9. Numbers are given. It is known that the number changes from -10 to 10 in increments of 5, and does not change. Calculate the sum and difference of the numbers and for all values ​​of and .

Solution. Unlike examples 3 and 6, here the number changes from -10 to 10 in increments of 5. This means that the number is a loop variable. First equal to -10 - this is the initial setting of the loop variable. Then it will change in steps of 5, etc. until the value 10 is reached - this corresponds to a change in the loop variable. Iterations must be repeated until the condition "" is met. So, it will take the following values: -10, -5, 0, 5, 10. The number will not be a loop variable, because and does not change according to the conditions of the problem. The flowchart result (with precondition) is presented in

The main blocks used to draw up algorithm diagrams are presented in the ESPD regulatory documents, mainly these

  • GOST 19.003-80 Schemes of algorithms and programs. Conventional graphic symbols
  • GOST 19.701-90 Schemes of algorithms, programs, data and systems. Conventions and execution rules



Basic blocks for compiling algorithms

Name Designation Description
Start, end, interruption of data processing or program execution
Performing an operation or group of operations that changes the value, form of presentation, or location of data
Use of previously created and separately described algorithms or programs
Converting data into a form suitable for processing (input) or displaying the results of processing (output)
Solution Choosing the direction of execution of an algorithm or program depending on some variable conditions
The decision block has 1 input and at least 2 outputs
Cycle boundariesThe symbol, consisting of two parts, represents the beginning and end of the cycle. Both parts of the symbol have the same identifier.
Conditions for initialization, increment, termination, etc. are placed inside the symbol at the beginning or end depending on the location of the operation testing the condition.
Preparation Performing operations that change instructions or a group of instructions in order to affect some subsequent function (setting a switch, modifying a register, initializing a program)
Explanation of the circuit element (or communication line)
When the circuit is highly saturated, individual flow lines between distant symbols can be broken off. In this case, the “Connector” symbol must be placed at the end (beginning) of the break. Inside the connector block is the name of the unique identifier.

Dimension a must be selected from the range 10, 15, 20 mm. It is allowed to increase size a by a multiple of 5 mm. Dimension b is 1.5a.

The main direction of flow in algorithm schemes is top-down, left-to-right. If the flow lines go in the main direction and do not have kinks, they do not need to be marked with arrows. In other cases, the direction of the flow line must be indicated with an arrow.

Entries within a symbol must be presented so that they can be read from left to right and top to bottom, regardless of the direction of flow.

In a schema, a symbol can be assigned an identifier, which must be placed to the left above the symbol.

Brief information about the symbol (description, clarification, or other cross-references to better understand the function of this part of the circuit) is allowed. The description of the symbol should be placed to the right above the symbol.

If it is necessary to merge flow lines, the merge location should be indicated by a dot or the symbol 0.


8.2. Algorithm flowcharts

When describing algorithms, flowcharts (Basic Flowchart) have long been successfully used. The construction of flowcharts of algorithms is regulated by GOST 19.701-90 (ISO 5807-85) "Unified system of program documentation. Algorithm diagrams of programs, data and systems. Conventions and execution rules." This state standard is based on the international standard "ISO 5807-85. Information processing – Documentation symbols and conventions for data, program and system flowcharts, program network charts and system resource charts".

According to GOST 19.701-90 under scheme 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 for 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 symbol 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