You get a bonus - 1 coin for daily activity. Now you have 1 coin

Basics of algorithmization Algorithm. flowcharts

Lecture



  • 1. Basics of algorithms


1.1 Stages of solving problems on a computer.

The solution of the problem is divided into stages:

  1. Formulation of the problem
  2. Formalization (mathematical formulation)
  3. Choice (or development) of a decision method
  4. Algorithm Development
  5. Drawing up a program
  6. Debugging program
  7. Calculation and processing of results
  1. When setting the task, it turns out the ultimate goal and develops a general approach to solving the problem. It turns out how many solutions the problem has and whether it has them at all. The general properties of the considered physical phenomenon or object are studied, the possibilities of this programming system are analyzed.
  2. At this stage, all the objects of the problem are described in the language of mathematics, the form of data storage is selected, all necessary formulas are compiled.
  3. The choice of an existing one or the development of a new solution method (and at the same time the personal stage is very important).
  4. At this stage, the solution method is written in relation to this problem in one of the algorithmic languages ​​(more often on the graphic one).
  5. We translate the solution of the problem into a language understandable to the machine.


1.2. Algorithm. Properties of algorithms.

The algorithm is a certain way organized sequence of actions, leading to the solution of the problem in a finite number of steps.
Algorithm properties:

  1. Certainty
  2. Discreteness
  3. Focus
  4. Extremity
  5. Mass character

The order of execution of the algorithm:

  1. Actions in the algorithm are performed in the order they are written.
  2. You can not swap any two actions of the algorithm
  3. It is impossible not to finish one action to the next.

For writing algorithms, special languages ​​are used:

  1. Natural language (verbal entry)
  2. Formulas
  3. Pseudocode
  4. Structures
  5. Syntax charts
  6. Graphic (language of flowcharts)
  1. Natural language:
    if the condition is then action1 otherwise action2
  2. Structogram:
    Basics of algorithmization Algorithm.  flowcharts
  3. Syntax diagram:
    Basics of algorithmization Algorithm.  flowcharts
  4. Graphic language:
    Basics of algorithmization Algorithm.  flowcharts

The compilation of algorithms in a graphical way is subject to two state standards:

  1. GOST 19.002-80, complies with international standard ISO 2636-73. Regulates the rules for drawing up flowcharts.
  2. GOST 19.003-80, complies with international standard ISO 1028-73. Regulates the use of graphic primitives.
Title Symbol (picture) Function performed (explanation)
1. Computing unit
Basics of algorithmization Algorithm.  flowcharts
Performs a computational action or group of actions.
2. Logic block
Basics of algorithmization Algorithm.  flowcharts
The choice of the direction of the algorithm, depending on the condition
3. I / O blocks
Basics of algorithmization Algorithm.  flowcharts
Input or output of data regardless of physical media
Basics of algorithmization Algorithm.  flowcharts
Data output to the printer
4. Start / End (In / Out)
Basics of algorithmization Algorithm.  flowcharts
Start or end of a program, enter or exit a subroutine
5. Predefined process
Basics of algorithmization Algorithm.  flowcharts
Calculations for a standard or custom routine
6. Block modification
Basics of algorithmization Algorithm.  flowcharts
Performing actions that change algorithm points
7. Connector
Basics of algorithmization Algorithm.  flowcharts
Specify a connection between interrupted lines within one page.
8. Interstitial Connector
Basics of algorithmization Algorithm.  flowcharts
Specifying a link between parts of a chart located on different pages


Rules for constructing flowcharts:

  1. The block diagram is built in one direction either from top to bottom or from left to right
  2. All turns of connecting lines are made at an angle of 90 degrees


1.3. Algorithmic design branching.

A branch is a control structure that organizes the execution of only one of the two specified actions, depending on the validity of a certain condition.
A condition is a question that has two possible answers: yes or no.
Record branching is performed in two forms: complete and incomplete.
Full form:
Basics of algorithmization Algorithm.  flowchartsBasics of algorithmization Algorithm.  flowcharts
Incomplete form:
Basics of algorithmization Algorithm.  flowchartsBasics of algorithmization Algorithm.  flowcharts
Example: find the smallest of the three numbers.
1 solution:
Basics of algorithmization Algorithm.  flowcharts
2 solution:
Basics of algorithmization Algorithm.  flowcharts


1.4. Algorithmic cycle design.

A cycle is a control structure that organizes multiple execution of a specified action.


Basics of algorithmization Algorithm.  flowcharts


Cycle "bye":
Basics of algorithmization Algorithm.  flowcharts
The execution of the “while” cycle begins with a condition check, therefore this kind of cycle is called a cycle with a precondition. The transition to the execution of an action is carried out only if the condition is fulfilled, otherwise the cycle is exited. We can say that the condition of the cycle "bye" is the condition for entering the cycle. In the particular case, it may be that the action has not been performed once. The condition of the cycle must be chosen so that the actions performed in the cycle would violate its truth, otherwise a loop will occur.
Looping - endless repetition of actions performed.
"To" cycle:
Basics of algorithmization Algorithm.  flowcharts
The execution of the cycle begins with the execution of the action. Thus, the loop body will be implemented at least once. After that, the condition is checked. Therefore, the “before” cycle is called a cycle with a postcondition. If the condition is not met, then it returns to performing actions. If the condition is true, the loop is exited. Thus, the condition of the "before" cycle is an exit condition. To prevent looping, it is necessary to provide for actions leading to the truth of the condition.
A cycle with a parameter , or a cycle with a counter , or an arithmetic cycle is a cycle with a known number of repetitions.
Basics of algorithmization Algorithm.  flowcharts
In the modification block, the law of change of the variable of the parameter is indicated.
Xo - the initial value of the parameter
h - step
Xn - the last parameter value
To create loops with a parameter, you must use the rules:

  1. The cycle parameter, its initial and final values ​​and step must be of the same type.
  2. It is forbidden to change the initial, current and final values ​​for the parameter in the body of the loop.
  3. It is forbidden to enter the cycle bypassing the modification block.
  4. If the initial value is greater than the final one, then the step is a negative number.
  5. After exiting the loop, the value of the parameter variable is undefined and cannot be used in further calculations.
  6. You can exit the loop without finishing it, then the variable parameter retains its last value.


1.5. Using loops with a parameter to handle arrays.

An array is an ordered structure for storing data of the same type.
The ordering of elements in an array occurs by their indices.
Index - the ordinal number of the element.
The array is specified by name (uppercase Latin letters), data type, and dimension.
Dimension - the maximum possible number of elements in the array. Only one element of the array can be accessed at a time. To do this, specify the name of the array and in parentheses the index of the element.
Arrays are divided into one-dimensional (linear) and two-dimensional.
A prototype in mathematics for a one-dimensional array is a vector. For two-dimensional - the matrix.
Example: calculate n!
Basics of algorithmization Algorithm.  flowcharts
Example: calculate a n
Basics of algorithmization Algorithm.  flowcharts

Example: enter array elements:
a) one-dimensional, dimension 10
Basics of algorithmization Algorithm.  flowcharts
b) two-dimensional, 5x5
Basics of algorithmization Algorithm.  flowcharts


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Algorithmization and programming. Structural programming. C language

Terms: Algorithmization and programming. Structural programming. C language