TechnologiesElectronics

Block diagram of the algorithm: programs, tasks, elements, construction

In the modern world of digital technology, programming is the basis for the operation of various computers, gadgets and other electronic equipment. And the ability to quickly and correctly draw up a block diagram of the algorithm is the foundation, the basis of this science. Such a scheme is a graphical model of the processes that must be performed by the equipment. It consists of separate function blocks that perform various functions (start / end, I / O, function call, etc.).

Algorithm and Algorithmization

In fact, the algorithm is the usual instruction about the sequence in which it is necessary to perform certain actions when processing the original data in the required result. Along with this term, the concept of algorithmization is often used. It is understood as a set of methods and techniques for drawing up a sequence for solving specific problems.

Often the algorithm is not used as an instruction for a computer, but as a scheme for performing any actions. This allows us to note the effectiveness and effectiveness of this method of solution, correct possible errors, and compare it with other similar solutions even before the introduction to the computer. In addition, the algorithm is the basis for compiling a program that must be written in a programming language, in order to further implement the process of processing information on a PC. To date, two practical ways of constructing such sequences have become known. The first is a step-by-step verbal description, and the second is a block diagram of the algorithm of the problem. The first of them was significantly less widespread. This is due to the lack of visibility and verbosity. The second way, on the contrary, is a very convenient means of displaying the sequence. It is widely distributed in both academic and scientific literature.

Elements of flowcharts

The flowchart of the program algorithm is a sequence of graphic symbols that prescribe the execution of specific operations, as well as the relationships between them. Inside each such image, information about the task to be performed is indicated. The sizes and configuration of graphic symbols, as well as the order of sequence design are regulated by GOST 19003-80 and GOST 19002-80.

Let's consider the basic elements of the flowchart of the algorithm (examples of their inscriptions are given in the photo).

1. A process is a computational action or a sequence of such actions.

2. The solution is to check the given condition.

3. Modification - the title of the cycle.

4. Predefined process - access to the procedure.

5. Document - print and output data.

6. Card - input information.

7. Input / Output - Input / Output of data.

8. Connector - rupture of flow lines.

9. Beginning / End-beginning, end, stop, start, input and output are used in auxiliary algorithms.

10. Comment - use to place explanatory inscriptions.

11. Vertical and horizontal flows are the direction of the sequence, the line of communication between the blocks.

12. Merge - connection of threads.

13. Interstitial connector - a label that symbolizes the transition to another sheet.

Drawing rules

The construction of the flowchart of the algorithm is carried out according to specific requirements prescribed by GOST. For example, when connecting graphic symbols, only horizontal or vertical lines are used. Streams from right to left and from bottom to top are marked by arrows. Other lines may not be marked. The distance between parallel flows should not be less than three millimeters, and between the remaining elements - not less than five millimeters. The dimensions of the blocks must be a multiple of five. The ratio of the horizontal to the vertical of the graphic symbol is 1.5. Sometimes it is allowed equal to two. For convenience of description, the graphic symbols should be numbered. By the nature of the connections, the types of block diagrams of the algorithm of a linear, cyclic and branching structure are distinguished.

Variables, constants and memory cells

For a better understanding of the principle of the algorithm, one can consider a simple automaton. It consists of a memory consisting of cells; A recording / reading head; CPU. What is the principle of operation of such a device? The head, having received an order from the processor, carries out writing data to a cell or reads a constant. In the simplest case this will be an arithmetic number. In addition, constants can be data structures, character strings, etc. A variable is a memory cell in which information is stored. During the execution of the algorithm, various data can be written in such a cell. On this principle, personal computers and other electronics are built. The algorithm for executing a task is a set of instructions for reading or writing information to these memory cells.

Arrays

Arrays are another kind of indexed variables. In fact, this is a collection of cells, which are united by a common designation. Arrays distinguish two-dimensional, three-dimensional, etc. The simplest of them is a series of consecutive cells. Such an array has its own name. Each element has its own index number. A constant written in a cell is called an array element.

The two-dimensional type resembles a matrix in its arrangement of elements. The cells in this array are characterized by two indices (this resembles a chess board with cell numbering). By the same principle, three-dimensional and more structures are realized.

Linear Algorithms

This type of sequence flowchart algorithms (examples are presented in this article) is characterized by execution from the beginning to the end from top to bottom. In this case, the machine performs the prescribed operations step by step. Each action is processed by the processor. In addition to calculations, he, if necessary, orders a writing / reading head where and what to write down and how to read. The end result is written to memory cells, each of which has its own index and stores its constant.

Branching algorithms

In practice, the linear type is extremely rare. Often, it is necessary to organize a sequence, which, depending on the given conditions, flows along one or another branch. A flowchart of a branched-type algorithm contains the "Solution" element, through which a certain condition is checked, and the more of them, the more branches of the sequence.

Flowcharts of algorithms: examples

Consider how the branched algorithm functions. As an example, take the function: z = y / x. It can be seen from the condition that this equation has one restriction - it is impossible to divide by zero. So you need to exclude this solution and warn the user about the error. First, a block diagram of the algorithm is compiled. It will consist of seven blocks. The first graphic symbol is "Start", the second is "Enter", here you should specify the values of X and Y. Then the "Solution" block follows, in which the condition is checked: X = 0. In this case, the automaton checks the cell with a constant, if the input value coincides with it, then the solution of the algorithm will go along the "Yes" branch. In this case, control is transferred to the fourth block, and the machine gives an "error", the work ends in the seventh character "End". If the result of the test is negative, then in the fifth graphic symbol the division process is performed and the value of Z is determined. In the sixth block, the result is displayed on the screen.

Cyclic algorithms

Often when solving problems, it is necessary to repeat the execution of an operation for the same dependency for different values of the variables and to make repeated passes along the same section of the circuit. Such areas are called cycles, and the algorithm is called cyclic. Using this method significantly reduces the sequence itself. Cyclic algorithms are usually divided into two types: with a previously unknown and previously known number of such passes.

Example of branched algorithm solution

Consider an example in which a block diagram of an algorithm with a previously unknown number of passes is given. To do this, it is necessary to solve the problem - to indicate the smallest number of terms in the series of natural numbers whose sum exceeds the number K. Such a block diagram of the algorithm consists of eight symbols. First, we introduce the value of the number K (N2). Then, in block 3, the variable Π gets the value "one", which means that the counting of natural numbers begins. And the cumulative amount of C in the beginning gets the value "zero". Further control is transferred to the fifth block, where the command is executed: C = C + P. That is, the values of cells C and II are summed, and the result is overwritten in C. After addition of the first term of this sequence in block 6, the condition is checked - does the sum exceed the specified number K? If the condition is not fulfilled, then control is transferred to the fourth block, where one is added to the variable P and the transition is again made to block # 5. This procedure will occur until the condition: C> K, that is, the accumulated amount exceeds the specified value. Variable II is the cycle counter. Then there is a transition to the block number 7, where the results of the work are printed.

Algorithms containing nested loop structures

Often, when solving the problem positively, it becomes necessary to create a cycle that contains another cycle in its body. This is considered the norm. Such elements are called nested loop structures. Their order can be quite large. It is determined by the method by which the solution of the necessary problem is achieved. For example, when processing a one-dimensional array, as a rule, a block diagram of the algorithm is constructed without nesting cycles. And nevertheless, in a number of cases, when solving similar problems, it becomes necessary to choose exactly such a variant of the solution. It should be noted that all nested loops, including the first one (external), must contain counters with different names. Outside of their cycle, they can be used as ordinary variables.

Auxiliary algorithms

This type of sequence is an analog of the language subroutine. The auxiliary algorithm has a name and parameters, which are called formal. The name is given to distinguish it among others, and the parameters perform the role of output and input mathematical functions. They are chosen in such a way that the full set of necessary quantities is exhausted. Often, the same formal parameter turns out to be both input and output. For example, in such an algorithm, an array can be fed to the input for processing. And in the resulting part, it can be represented in an altered form as an output parameter. Among the algorithms of the auxiliary type, functions and procedures are distinguished.

Algorithm decomposition

By this term we mean the decomposition of the general scheme of the algorithm into auxiliary (functions and procedures) and the head one. This method is very simple, when the algorithm is set by a block diagram - first, it isolates the sites responsible for the main work. The most complex stages are formalized as functions and procedures of the upper level. Then they are divided into low-level elementary areas. Here the principle "from complex to simple" works. This is done until the algorithm is parsed into the simplest elements. Typically, the sequence decomposition solution consists of three main steps: inputting data, sorting the array, outputting the sorted array. The first and last stages, because of their elementarity, do not need to be decomposed, so they are performed in the head algorithm. But the second is a very complex independent piece of computing, so it is usually taken out as a separate block. The sorting stages, in turn, are divided into two parts: the establishment of the necessity of carrying out the procedure (N-1) -fold passage through the given array and finding the smallest element in the considered fragment of the array, and then rearranging it with the initial element of the section. Since the last stage is repeated many times, it is formalized as a separate procedure.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.