How to set up smartphones and PCs. Informational portal
  • home
  • Mistakes
  • The concept of the algorithm executor is a system of commands for the executor. Types of Algorithms - Knowledge Hypermarket

The concept of the algorithm executor is a system of commands for the executor. Types of Algorithms - Knowledge Hypermarket

Algorithm and its properties.

Algorithm- a clear and precise instruction to the performer to execute the final sequence of commands leading from the initial data to the desired result.

Algorithm performer- this is the object or subject for which the algorithm is designed.

The performer's command system (SCI) is the entire set of commands that the performer can execute.

Algorithm properties: clarity, accuracy, finiteness.

Clarity: the algorithm is composed only of the commands included in the executor's USP.

Accuracy: each command of the control algorithm determines the unambiguous action of the executor.

Finiteness (or effectiveness): the execution of the algorithm must lead to a result in a finite number of steps.

Performer environment: The environment in which the performer operates.

A certain sequence of actions of the performer is always applied to some initial data. For example, to prepare a dish according to a recipe, you need the appropriate products (data). To solve a mathematical problem (solution of a quadratic equation), you need initial numerical data (coefficients of the equation).

Full data set: a necessary and sufficient set of data to solve the problem (obtaining the desired result).

Ways of writing algorithms.

The most common methods are: graphic, verbal and in the form computer programs.

Graphical way involves the use of certain graphic symbols - blocks.

Block name Block designation Content
Process
Data processing
Decision-making
Logical block for checking the truth or falsity of some condition
Data transfer
Input or output of information
Start, stop
Start or end of the program
Modification
Organization of the cyclic process - cycle header

The collection of blocks forms the so-called block diagram of the algorithm.

Word entry algorithms is oriented, first of all, to a human performer and allows different recording of prescriptions, but at the same time, the recording must be sufficiently accurate.

When writing algorithms in the form programs for computers, programming languages ​​are used - coding systems for prescriptions and rules for their use. For writing algorithms in the form of programs, a high degree of formalization is characteristic.

Algorithms for working with quantities. Basic algorithmic structures.

A value is a single information object that has a name, a value, and a type.

The executor of algorithms for working with values ​​can be a person or a special technical device, such as a computer. This performer must have memory for storing values.

The values ​​are fixed and variable.

Constant value (constant) does not change its value during the execution of the algorithm. A constant can be denoted by its own value (numbers 10, 3.5) or by a symbolic name (number ).

variable can change the value during the execution of the algorithm. A variable is always denoted by a symbolic name (X, A, R5, etc.).

Value type defines the set of values ​​that a value can take, and the set of actions that can be performed on that value. Basic types of quantities: integer, real, symbolic, logical.

Expression- a record that defines the sequence of actions on values. An expression can contain constants, variables, operation signs, functions. Example:

A + B; 2*X-Y; K + L - sin (X)

An assignment command is an executor command that results in a variable receiving a new value. Command format:

variable name>:=expression>

The assignment command is executed in the following order: first it is calculated, then the resulting value is assigned to a variable.

Example. Let variable A have the value 6. What value will variable A get after executing the command: A:= 2 * A - 1?
Solution. The expression 2 * A - 1 with A = 6 will give the number 11. So the new value of the variable A will be 11.

In what follows, it will be assumed that the executor of algorithms for working with quantities is a computer. Any algorithm can be built from commands assignments, input, output, branching And cycle.

Input command- a command by which the values ​​of variables are set through input devices (for example, a keyboard).

Example: input A - input of the value of variable A from the computer keyboard.

Output Command: The command by which the value of the value is displayed on the computer's output device (such as a monitor).

Example: output X - the value of the variable X is displayed on the screen.

Branch command- divides the algorithm into two paths depending on some condition; then the execution of the algorithm goes to a common continuation. Branching is complete and incomplete. Description of branching in flowcharts and in the Algorithmic language:

Here, a series refers to one or more consecutive commands; kv - the end of the branch.

Loop Command provides repeated execution of a sequence of commands (loop body) according to some condition.

Loop with precondition- a loop, the execution of which is repeated while the condition of the loop is true:

Loop with parameter- repeated execution of the loop body while the integer parameter runs through the set of all values ​​from the initial (In) to the final (Ik):

Example. Given two simple fractions. Write an algorithm for obtaining a fraction that is the result of their division.
Solution. In algebraic form, the solution to the problem is as follows:
a / c: c / d \u003d a * d / b * c \u003d m / n
The initial data are four integer values: a, b, c, d. The result is two integers m and n.

alg division of fractions
whole a, b, c, d, m, n
start input a, b, c, d
m:=a*d
n:=b*c
output "Numerator=", m
output "Denominator=", n
koi

Please note that to display text (any character sequence), it must be written in quotes in the command output.

  1. Efimova O., Morozov V., Ugrinovich N. Course of computer technology with the basics of informatics. Textbook for senior classes. - M.: LLC "AST Publishing House"; ABF, 2000
  2. Taskbook-workshop on informatics. In 2 volumes / Ed. I.Semakina, E.Khenner. - M.: Basic Knowledge Laboratory, 2001
  3. Ugrinovich N. Informatics and information technologies. Grade 10-11 - M .: Basic Knowledge Laboratory, JSC "Moscow textbooks", 2001

Tasks and tests on the topic "Algorithms and performers"

  • Executive Management Draftsman - Algorithms Grade 6

    Lessons: 4 Assignments: 9 Tests: 1

  • 2 Tasks: 9 Tests: 1

Dear student!

Knowledge of the Topic "Algorithms and performers" is necessary first of all for the further study of programming. The QBasic programming language was chosen as the basis for learning programming. We abandoned the idea of ​​including Visual Basic or any other object-oriented programming language in our course, since such an approach has not yet been widely used in most secondary schools in the Russian Federation. In addition, the principles of classical programming in Dos are at the heart of object-oriented programming.

Our course is designed for a general education program. When preparing for entrance exams in information technology to universities, it is necessary to familiarize yourself with the specifics of studying programming in this university. In some cases, an in-depth study of a number of topics is necessary, such as "Arrays" for example. This should be taken into account when studying the literature on programming, perhaps you should use the methodological recommendations for preparing for exams, which are currently published in most higher education institutions.

In conclusion, we note that the achievement of "aerobatics" in programming is possible only with constant practice and solving specific applied problems.

The word "algorithm" comes from the name of the Arab mathematician of the 9th century al-Khwarizmi, who formulated the rules for performing arithmetic operations.

Algorithm- an exact and understandable instruction to the performer to execute a final sequence of commands leading from the initial data to the initial result.

Examples: daily routine, cooking order, instructions, etc.)

Algorithm performer is the one who executes the algorithm (human, animal, machine, computer).

Executor command system- this is the whole set of commands that the performer can execute (understand). The algorithm can be built only from commands included in the command system of the executor.

For example, the executor Robot can execute commands forward, backward, left, right, paint over. It moves across a cellular field bounded by a wall and containing walls. The robot cannot pass through the wall.

Algorithm properties:

1.Efficiency (finiteness)– the possibility of obtaining a result from the initial data in a finite number of steps. (For example, when executing the addition algorithm, 2 numbers should get the sum).

2.mass character– the possibility of applying the algorithm to a large number of different initial data. (For example, You can add any 2 numbers, knowing the addition algorithm.)

3.determinism(definiteness, accuracy) - each team must uniquely determine the action of the performer.

4.Clarity- the command must be written in a language understandable to the computer.

5.discreteness– splitting the algorithm into separate commands.

Algorithm writing methods:

1) In natural language - recording in the form of separate commands in a language understandable to a person.

2) Graphic - in the language of block diagrams, using geometric shapes (oval, rectangle, parallelogram, rhombus).

3) In an algorithmic language - a language for writing algorithms for teaching programming. Teams are written in Russian.

4) In a programming language, a program. Programming languages: Basic, Pascal, C, Visual Basic.

B7. Basic algorithmic structures: following, branching, loop; image on block diagrams. Splitting tasks into subtasks. Auxiliary algorithms.

Algorithmic constructions. Within the algorithms, groups of steps can be distinguished that differ in their internal structure - algorithmic constructions.

Basic algorithmic constructions are a linear sequence of steps (or following), a branch, and a loop.

An algorithm in which commands are executed sequentially one after another is called linear algorithm.

This is how a linear algorithm looks like in the flowchart language:

Example: algorithm for turning on the computer:

  1. Turn on the computer power (press the button on the surge protector).
  2. Turn on the monitor, printer.
  3. Press the Power button on the system unit.
  4. Wait for the operating system to load and the desktop to appear.
  5. Get to work.

In this algorithm, all actions must be performed sequentially one after another: you cannot start working if the power or monitor is not turned on.

into an algorithmic structure branching» included condition, depending on the truth of the condition, one or another sequence of commands (series) is executed.

A condition is a statement that can be true or false. In a condition, two numbers, two strings, two variables or string expressions are compared with each other using the comparison operators (>,<, =, >=, <=).

Algorithmic notation: IfCondition Then Series 1 (If Condition true, then it executes Series 1, if Condition false, nothing is done). Example: If today is Sunday, then you don't have to go to school. Full branching form

In algorithmic structures cycle includes a series of commands that are executed repeatedly. This sequence of commands is called loop body.

Cyclic algorithmic structures are of two types:

  • cycles with counter, in which the loop body is executed a certain number of times;
  • conditional loops, in which the loop body is executed as long as the condition is met.

Loop with counter- is used when it is known in advance how many repetitions of the loop body must be performed.

The concept of an algorithm. Algorithm implementers. Properties of algorithms

The concept of an algorithm is as fundamental to computer science as the concept of information. There are many different definitions of the algorithm, since this concept is quite broad and is used in various fields of science, technology and everyday life.

An algorithm is a clear and precise sequence of actions that describes the process of transforming an object from an initial state to a final one.

An algorithm is an exact description of the sequence of actions aimed at solving a given problem intended for a specific performer.

Contractor An algorithm can be either a person (cooking recipes, various instructions, algorithms for mathematical calculations), or a technical device. Various machines (computers, industrial robots, modern household appliances) are formal executors algorithms. A formal executor is not required to understand the essence of the problem being solved, but the exact execution of a sequence of commands is required.

The algorithm can be written in various ways (verbal description, graphic description - block diagram, program in one of the programming languages, etc.). A program is an algorithm written inprogramming language .

To create an algorithm (program), you need to know:

    a complete set of initial data of the task (the initial state of the object);

    the purpose of creating the algorithm (the final state of the object);

    the executor's command system (that is, the set of commands that the executor understands and can execute).

The resulting algorithm (program) must have the following set of properties:

    discreteness (the algorithm is divided into separate steps - commands);

    uniqueness (each command determines the only possible action of the performer);

    intelligibility (all commands of the algorithm are included in the command system of the executor);

    efficiency (the performer must solve the problem in a finite number of steps).

Most algorithms also have the property mass character (using the same algorithm, you can solve many problems of the same type).

Ways to describe algorithms

It was noted above that the same algorithm can be written in different ways. You can write an algorithm natural language. In this form, we use recipes, instructions, etc. To write algorithms intended for formal executors, special programming languages. Any algorithm can be described graphically in block diagram form. For this, a special notation system has been developed:

Designation

Description

Notes

Beginning and end of the algorithm

Data input and output.

Data output is sometimes referred to differently:

Action

In computational algorithms, this is the assignment

Fork

Fork - a component necessary for the implementation of branches and loops

Starting a Loop with a Parameter

Sample Process

In programming, procedures or subroutines

Transitions between blocks

Let us give an example of a description of the algorithm for summing two quantities in the form of a block diagram:

This way of describing the algorithm is the most clear and understandable to a person. Therefore, algorithms of formal executors are usually developed first in the form of a block diagram, and only then a program is created on one ofprogramming languages .

Typical algorithmic structures

The programmer has the ability to construct and use non-typical algorithmic structures, however, this is not necessary. Any arbitrarily complex algorithm can be developed on the basis of three typical structures: following, branching, and repeating. In this case, the structures can be located sequentially one after another or nested in each other.

Linear structure (following)

The simplest algorithmic structure is linear. In it, all operations are performed once in the order in which they are written.

branching

IN full branching there are two options for the executor's actions depending on the value of the logical expression (condition). If the condition is true, then only the first branch will be executed, otherwise only the second branch.

The second branch may be empty. Such a structure is called incomplete branching or traversal.

From several branches, you can construct the structure " choice” (multiple branching), which will choose not from two, but from more options for the performer, depending on several conditions. It is essential that only one branch is executed - in such a structure, the order of the conditions becomes important: if several conditions are met, then only one of them will work - the first from the top.

Cycle (repetition)

Cycleallows you to organize repeated repetition of the same sequence of commands- it is called the body of the cycle. In various types of cyclic algorithms, the number of repetitions may depend on the value of the logical expression (condition) or may be rigidly specified in the structure itself. There are cycles: before», « till», cycles with a counter. In "until" and "while" loops, a logical expression (condition) may precede the loop body ( loop with precondition) or terminate the loop ( loop with postcondition).

Cycles« before» - repetition of the loop body until the condition is met:

Cycles « till» - repetition of the loop body while the condition is met(true):

Cycles with a counter(with parameter)– repetition of the loop body a given number of times:

Auxiliary algorithm (subroutine, procedure)

Helper Algorithm is a module that can be repeatedly accessed from the main algorithm. The use of auxiliary algorithms can significantly reduce the size of the algorithm and simplify its development.

Methods for developing complex algorithms

There are two methods for developing complex algorithms:

Method of sequential detailing of the problem(“top-down”) is that the original complex task is divided into subtasks. Each of the subtasks is considered and solved separately. If any of the subtasks are complex, they are also broken down into subtasks. The process continues until the subtasks are reduced to elementary ones. The solutions of individual subtasks are then assembled into a single algorithm for solving the original problem. The method is widely used, as it allows several programmers to develop a common algorithm at the same time, solving local subtasks. This is a necessary condition for the rapid development of software products.

assembly method("bottom-up") is to create a set of software modules that implement the solution of typical tasks. When solving a complex problem, a programmer can use the developed modules as auxiliary algorithms (procedures). In many programming systems Similar sets of modules already exist, which greatly simplifies and speeds up the creation of a complex algorithm.

Algorithms and control processes

Control - purposeful interaction of objects, some of which are control, others are controlled.

In the simplest case, there are two such objects:

From a computer science point of view control actions can be considered as control information. The information may be transmitted in the form of commands. A sequence of commands to control an object, leading to a predetermined goal, is called control algorithm. Therefore, the control object can be called the executor of the control algorithm. In the considered example, the control object works "without looking" at what is happening with the control object ( open loop control open. Another control scheme can take into account information about the processes occurring in the control object:

In this case, the control algorithm must be flexible enough to analyze this information and decide on its further actions depending on the state of the control object ( feedback control). This control scheme is called closed.

In more detail, management processes are studied are considered cybernetics. This science claims that the most diverse management processes in society, nature and technology occur in a similar way, obey the same principles.

Topic start

Please pause AdBlock on this site.

In this lesson, we will analyze some theoretical concepts that formalize the concept of programming. At the same time, we will more precisely formulate the main task of your training.

To get started, I suggest you play a little with the next children's toy. Go through the first five tasks, go back and continue reading the lesson.

Fig.1 Screenshot of the playing field on code.org

I hope everything worked out for you. Now, using this example, we will describe a few basic concepts:

  • executor;
  • executor's command system;
  • algorithm.

In the toy we control a red bird. The task of each stage is to get the bird to the pig. The bird can perform certain commands, for example: move forward, turn left, turn right, etc.

A person, machine, or device that can execute some command is called an executor. In this toy, obviously, the performer is a bird. A set of commands that an executor understands and can execute is called executor's command system.

The sequence of commands that an executor must execute to solve a problem is called an algorithm.

It is necessary to focus on several points.

An executor can execute only those commands that are included in his command system.

This means, for example, that you cannot write to a bird performer: “Go to the pig!”. You can write it down more precisely, but nothing will happen, because. the executor of such commands does not know.

You can write the available commands in any order that you deem correct. Your task as a programmer is to divide a large complex task into small separate steps, each of which will be understandable to the performer. The principle of "divide and conquer" works again.

The performer performs exactly what the algorithm prescribes to him.

The performer-bird is very trusting. It doesn't question what you write in the program. If, for example, you forget to turn the bird around, it will crash into the wall. So you have to take care of everything yourself.

Your future programs will often not work the way you intended. Mistakes happen to everyone. It is important to understand here that this is not a computer fool, but you made a mistake in the algorithm. Do not be like bad programmers who always blame the program for everything.

Now let's move on from a visual example to computer realities. We write programs for the computer, which means that the computer in our case is the executor. The command system is the standard functions and constructs of the C language.

What is the main goal of your learning the basics of programming? Master the skill of algorithmic thinking. That is, to learn how to write down the solution of various problems in the form of an algorithm for a specific performer (in our case, a computer).

So let's recap:

computer program- an algorithm for solving a problem, written in a programming language.

An algorithm is a precise description of the order of actions that an executor must perform in order to solve a problem.

An executor is a person or some device that can understand and execute a certain set of commands.

TOPIC 8. BASICS OF ALGORITHMS AND PROGRAMMING

8.1. The concept of the algorithm and the executor of algorithms. Properties of algorithms

"Algorithm" is a fundamental concept of computer science. The idea of ​​it is necessary for the effective application of computer technology to the solution of practical problems. An algorithm is an instruction to an executor (a person or an automaton) to perform a precisely defined sequence of actions aimed at achieving a given goal. An algorithm is a rule formulated in a certain language that indicates actions, the sequential execution of which leads from the initial data to the desired result. Meaning of the word algorithm very similar to the meaning of the words recipe, process, method, method. However, any algorithm, unlike a recipe or method, necessarily has the following properties.
Algorithm properties (distinguishing it from any other prescriptions): intelligibility(for a specific artist); discreteness(commands are sequential, with precise fixation of the moments of the beginning and end of the command execution); accuracy(after the execution of each command, it is known for sure whether the execution of the algorithm is completed or which command should be executed next); efficiency(after a finite number of steps the problem is solved or it becomes clear that the solution process cannot be continued): mass character(the algorithm applies uniformly to any particular problem statement for which it is designed).
1. Discreteness - splitting the algorithm into a number of separate completed actions - steps. The execution of the algorithm is divided into a sequence of completed actions - steps. Each action must be completed by the executor of the algorithm before it proceeds to the execution of the next action.
2. Accuracy - unambiguous indications. At each step, the transformation of the objects of the executor's environment obtained at the previous steps of the algorithm is uniquely defined. If the algorithm is repeatedly applied to the same set of input data, then the output is the same result each time. The record of the algorithm should be such that at each step of its execution it is known which command should be executed next.
3. Clarity - unambiguous understanding and execution of each step of the algorithm by its executor. The algorithm must be written in a language understandable to the performer.
4. Efficiency - the obligatory receipt of the result in a finite number of steps. Each step (and the algorithm as a whole) after its completion provides an environment in which all objects are uniquely defined. If this is impossible for some reason, then the algorithm should report that there is no solution to the problem. The work of the algorithm must be completed in a finite number of steps. Computer science operates only with finite objects and finite processes, so the question of considering infinite algorithms remains outside the scope of the theory of algorithms. 5. Mass character - the application of the algorithm to the solution of a whole class of tasks of the same type.
The executor's command system is a precisely described environment, including the formulation of the problem to be solved, a list of objects involved in the condition of the problem and in its solution, and the executor's capabilities: properties of objects that he can recognize and actions that he can perform. The formal execution of the algorithm is performed by the compiler or interpreter, checking the semantics.

8.2. Ways to write an algorithm

In practice, the following forms of writing algorithms are the most common:
1) graphic record (block diagrams);
2) verbal notation (pseudocodes);
3) programming language.
The verbal form of the algorithm is a description in natural language of successive stages of data processing. The verbal method is not widely used, since such descriptions are not strictly formalizable, and allow ambiguous interpretation of individual prescriptions. An algorithm written using pseudocode is a semi-formalized description in a conditional algorithmic language, including both the main elements of the programming language and natural language phrases, common mathematical notation, and others.
The graphic form of the record, also called the algorithm diagram, is an image of the algorithm in the form of a sequence of interconnected functional blocks, each of which corresponds to the execution of one or more actions. Graphic notation is more compact and visual than verbal notation. In the algorithm scheme, each type of action corresponds to a geometric figure. The figures are connected by transition lines that determine the sequence of actions.
The graphical form of the record, also called a block diagram or flowchart of an algorithm, is an image of an algorithm in the form of a sequence of interconnected functional blocks, each of which corresponds to the execution of one or more actions.
In what follows, we will use block diagrams in. They allow you to present algorithms in a more visual form, this makes it possible to analyze their work, look for errors in their implementation, etc. Flowcharts always have Start And the end, denoted by ellipses, between them - a sequence steps algorithm connected arrows.

Steps happen unconditional(represented by rectangles, parallelograms) and conditional(represented by diamonds). Two arrows always come out of the rhombus - one means the further path, if the condition is met (usually denoted by the word "yes" or "+"), the other - non-fulfillment (by the word "no" or "-"). Entering from the keyboard or displaying the value of an expression on the screen is represented by a parallelogram. The command that performs the processing of actions (assignment command) is displayed in a rectangle.

If the solution to the problem is complex and long enough, then the algorithm can turn out to be very large. This can be avoided by replacing some complete sequence of steps of the algorithm with blocks that will be auxiliary algorithms. The block is usually not elementary, its dimensions are chosen depending on the need, however, if it is correctly composed, it has all the necessary features of an algorithmic step: it has an entry point (a clearly defined beginning) and can be conditional or unconditional. Different blocks of the algorithm are connected to each other only through entry and exit points, so if the block correctly solves its problem, then its internal structure is not essential for the rest of the algorithm. Such a block representation is especially useful in the early stages of solving complex problems, when the detailing of the blocks is done later and, possibly, by other developers.
A programming language is a language used to formally write algorithms. Most programming languages ​​are algorithmic languages. Writing an algorithm in an algorithmic language is called a program.
The language used to formally write algorithms is called algorithmic language. When describing any language (including natural, for example, Russian, English, etc.), the following concepts are used: alphabet, syntax And semantics.
Alphabet language is the set of the simplest signs that can be used in the texts of this language. A sequence of alphabetic characters is called word. The rules by which words are formed from the alphabet are called grammar. Himself language is the set of all words written in the given alphabet according to the given grammar.
Syntax- this is a set of rules that determine the possible combinations (constructions) of the letters of the alphabet. To describe the syntax of a language, as a rule, another language (metalanguage) or syntax diagrams are used.
Semantics is a set of rules that determine the meaning (meaning) of individual language constructs.
One of the most common algorithmic languages ​​is Pascal, which is useful for both beginners and experienced programmers. Programming training is most often based on this language.

8.3. Basic algorithmic constructions

The most understandable structure of the algorithm can be represented using a flowchart, which uses geometric shapes (blocks) interconnected by arrows indicating the sequence of actions. Certain standards for block graphics have been adopted. For example, an information processing command is placed in a block in the form of a rectangle, a condition check is placed in a rhombus, input or output commands are placed in a parallelogram, and an oval denotes the beginning and end of the algorithm.
The structural elementary unit of the algorithm is a simple command denoting one elementary step of processing or displaying information. A simple instruction in the schematic language is represented as a function block.

This block has one entry And one way out. From simple commands and checking conditions, compound commands are formed that have a more complex structure and also one entry and one exit.
The structural approach to the development of algorithms determines the use of only basic algorithmic structures (constructions): following, branching, repetition, which should be formalized in a standard way.

Consider the basic structures of the algorithm.
Command following consists of simple commands only. In the figure, simple commands have a symbol S1 And S2. Linear algorithms are formed from the following commands. An example of a linear algorithm would be to find the sum of two numbers entered from the keyboard.

Command branching- this is a composite command of the algorithm, in which, depending on the condition P, either one S1, or other S2 action. Branching algorithms (branching algorithms) are composed of the following commands and branching commands. An example of a branching algorithm would be to find the larger of two numbers entered from the keyboard.

The branch command can be complete or incomplete. The incomplete form of the branch command is used when an action needs to be performed. S only if conditions are met P. If condition P is not respected, then the branch command terminates without performing an action. An example of an incomplete form branching command would be to halve only an even number.

Command repetition is a composite command of the algorithm, in which, depending on the condition R it is possible to perform the action multiple times S. Cyclic algorithms (repetition algorithms) are composed of follow commands and repetition commands. The figure shows a repetition command with a precondition. It is called so because the condition is checked first, and only then the action is performed. Moreover, the action is performed while the condition is met. An example of a cyclic algorithm may be as follows. While positive numbers are entered from the keyboard, the algorithm performs the calculation of their sum.
The repetition command with a precondition is not the only one possible. A variation of the repeat command with a precondition is the repeat command with a parameter. It is used when the number of repetitions of an action is known. In the block diagram of a repeat command with a parameter, the condition is written not in a diamond, but in a hexagon. An example of a cyclic algorithm with a parameter would be finding the sum of the first 20 natural numbers.

In a repeat command with a postcondition, the action is performed first S and only then, the condition is checked P. Moreover, the action is repeated until the condition is met. An example of a repeat command with a postcondition would be to decrease a positive number until it is non-negative. As soon as the number becomes negative, the repeat command ends its work.
By connecting only these elementary constructions (sequentially or by nesting), it is possible to "assemble" an algorithm of any degree of complexity.


Each specified construction can be implemented without changes in the structure in any programming language, for example, in Pascal and BASIC. Therefore, it is necessary to correctly compose an algorithm using a flowchart, and only then, knowing how commands are written in a particular programming language, type a program on a computer and get the result by running it for execution.

8.4. Linear algorithm

Let us give an example of writing an algorithm in the form of a flowchart, pseudocodes and in the Pascal language. Manual testing and selection of a test system are performed similarly to the previous task.


8.5. Branching Algorithm

Let's give an example of writing a branching algorithm for finding the largest of two numbers.


8.6. Cyclic algorithm

Consider an algorithm for finding the sum of the first natural odd numbers up to n. Let's represent the algorithm in three ways: in the form of a flowchart, a school algorithmic language, and in the Pascal programming language.


The flowchart consists of the following basic structures: two compound commands (a follow command and a repeat command with a precondition), then a simple command. All commands are connected in series. The constructs are designed in a standard way, so they are easy to recognize and translate into a programming language. Each design has one input and one output.
Dotted arrows in the table reflect the sequence of execution of the technological chain. After writing the algorithm in the form of a flowchart, each command is translated into a school algorithmic language, and only then into a programming language.
We write an algorithm for calculating the sum of the first n natural numbers. To do this, we use a loop with a parameter, since it is known in advance how many times the command to find the sum will be executed. In all links of the chain, we will change the "while" loop to the "for" loop and give an example of the translation of the algorithm from the flowchart language into the school algorithmic language and into the Pascal programming language.


Consider finding the number of natural numbers whose sum is not greater than a given one. To do this, we use the repetition command with a postcondition.


Questions for self-control

  1. The concept of an algorithm. Algorithm properties. Algorithm example. The concept of "variable".
  2. assignment operator. Examples.
  3. Programming styles (logical, functional).
  4. Concept of subroutine, module and object
  5. What is a variable? Variable naming conventions in Pascal. Examples.
  6. assignment operator. Writing expressions in Pascal. Examples. Explain how the operator x:=x+1;
  7. Input and output operators in Pascal. Examples. Formatted output.
  8. Conditional operator ( if). Example. Compare with operator case.
  9. Choice operator. Example. Compare with operator if.
  10. Boolean expressions. Operations or, and And not. Examples. Truth table.
  11. Numeric types of variables in Pascal. Type conversion rules. Examples.
  12. Boolean data type. Example of use in the program. Character data type. Example. Functions chr And order, succ And pred.
  13. Arrays. Definition. Array indexes. Array declarations. Accessing array elements. One-dimensional and two-dimensional arrays. Examples. Similarities and differences between arrays and strings.
  14. Procedures. Definition. Why are procedures needed? Examples. Procedure description rules. Compare procedures and functions.

Top Related Articles