Execution of the algorithm for a specific executor decision. Computer science and information technology. Ways to describe algorithms

Keywords:

  • algorithm
  • properties of the algorithm
    • discreteness
    • clarity
    • certainty
    • effectiveness
    • mass character
  • executor
  • performer characteristics
    • range of tasks to be solved
    • Wednesday
    • operating mode
    • command system
  • formal execution of the algorithm

3.1.1. Algorithm concept

Every person in Everyday life, in study or at work, solves a huge number of problems of varying complexity. Complex problems require a lot of thought to find a solution; A person solves simple and familiar tasks without thinking, automatically. In most cases, the solution to each problem can be divided into simple stages (steps). For many such tasks (installation software, assembling a cabinet, creating a website, operating a technical device, purchasing an airline ticket via the Internet, etc.) have already been developed and offered step by step instructions, which, when executed consistently, can lead to the desired result.

Example 1. The problem “Find the arithmetic mean of two numbers” is solved in three steps:

  • think of two numbers;
  • add two numbers in mind;
  • divide the resulting amount by 2.

Example 2. The task “Deposit money into your phone account” is divided into the following steps:

  • go to the payment terminal;
  • select a telecom operator;
  • enter a phone number;
  • check the entered number is correct;
  • insert a banknote into the bill acceptor;
  • wait for a message about money being credited to your account;
  • receive a check.

Example 3. The stages of solving the problem “Draw a funny hedgehog” are presented graphically:

Finding the arithmetic mean, depositing money into a telephone account and drawing a hedgehog are, at first glance, completely different processes. But they have a common feature: each of these processes is described by a sequence of brief instructions, the strict adherence to which allows you to obtain the required result. The sequences of instructions given in examples 1-3 are algorithms for solving the corresponding problems. The executor of these algorithms is a person.

The algorithm can be a description of a certain sequence of calculations (example 1) or steps of a non-mathematical nature (examples 2-3). But in any case, before its development, the initial conditions(input data) and what is to be obtained (result). We can say that an algorithm is a description of the sequence of steps in solving a problem, leading from the initial data to the required result.

In general, the algorithm’s operation diagram can be represented as follows (Fig. 3.1):

Rice. 3.1.
General scheme of the algorithm

Algorithms are the rules of addition, subtraction, multiplication and division of numbers, grammatical rules, rules of geometric constructions, etc., studied in school.

Animations “Working with an algorithm”, “Greatest common divisor”, “Least common multiple” (http://school-collection.edu.ru/) will help you remember some algorithms studied in Russian language and mathematics lessons.

Example 4. Some algorithm leads to the fact that from one chain of characters a new chain is obtained as follows:

  1. The length (in characters) of the source string of characters is calculated.
  2. If the length of the original chain is odd, then the number 1 is added to the original chain on the right, otherwise the chain does not change.
  3. The symbols are swapped in pairs (the first with the second, the third with the fourth, the fifth with the sixth, etc.).
  4. The number 2 is added to the right of the resulting chain.

The resulting chain is the result of the algorithm.

So, if the initial chain was A#B, then the result of the algorithm will be the chain #A1B2, and if the initial chain was ABC@, then the result of the algorithm will be the chain BA@B2.

3.1.2. Algorithm executor

Each algorithm is designed for a specific performer.

There are formal and informal performers. A formal performer always performs the same command in the same way. An informal executor can carry out a command in different ways.

Let us consider in more detail the set of formal performers. Formal performers are extremely diverse, but for each of them the following characteristics can be specified: the range of tasks to be solved (purpose), environment, command system and mode of operation.

Range of tasks to be solved. Each performer is created to solve a certain range of problems - constructing chains of symbols, performing calculations, constructing drawings on a plane, etc.

Artist Environment. The area, setting, conditions in which the performer operates are usually called the environment of the given performer. The source data and results of any algorithm always belong to the environment of the performer for whom the algorithm is intended.

Executor command system. An instruction to a performer to perform a separate completed action is called a command. The set of all commands that can be executed by some executor forms the system of commands for this executor (SKI). The algorithm is compiled taking into account the capabilities of a specific performer, in other words, in the system of commands of the performer who will execute it.

Performer operating modes. For most performers, direct control modes and program control. In the first case, the performer waits for commands from a person and immediately executes each received command. In the second case, the performer is first given a complete sequence of commands (program), and then he executes all these commands in automatic mode. A number of performers work only in one of the named modes.

Let's look at examples of performers.

Example 5. Performer The turtle moves on the computer screen, leaving a trace in the form of a line. The Turtle's command system consists of two commands:

    Forward n (where n is an integer) - causes the Turtle to move n steps in the direction of movement - in the direction in which its head and body are facing;

    Right m (where m is an integer) - causes the Turtle's movement direction to change by m degrees clockwise.

Record Repeat k [<Команда1> <Команда2> ... <Командаn>] means that the sequence of commands in brackets will be repeated k times.

Think about what figure will appear on the screen after the Turtle completes the following algorithm.

    Repeat 12 [Right 4 5 Forward 20 Right 45]

Example 6. The system of executor commands The computer consists of two commands, which are assigned numbers:

    1 - subtract 1
    2 - multiply by 3

The first of them decreases the number by 1, the second increases the number by 3 times. When writing algorithms, for brevity, only command numbers are indicated. For example, algorithm 21212 means the following sequence of commands:

    multiply by 3
    subtract 1
    multiply by 3
    subtract 1
    multiply by 3

Using this algorithm, the number 1 will be converted to 15: ((1-3-1)-3-1)-3 = 15.

Example 7. Performer Robot operates on a checkered field, between adjacent cells there may be walls. The robot moves along the cells of the field and can perform the following commands, which are assigned numbers:

    1 - Up
    2 - Down
    3 - Right
    4 - Left

When performing each such command, the Robot moves to an adjacent cell in the indicated direction. If there is a wall in this direction between the cells, then the Robot is destroyed. What will happen to the Robot if it executes the sequence of commands 32323 (here the numbers indicate command numbers), starting to move from cell A? What sequence of commands should the Robot execute in order to move from cell A to cell B without collapsing when it hits the walls?

When developing an algorithm:

  1. objects appearing in the problem are identified, properties of objects, relationships between objects and possible actions with objects;
  2. the initial data and the required result are determined;
  3. the sequence of actions of the performer is determined, ensuring the transition from the initial data to the result;
  4. the sequence of actions is recorded using commands included in the executor’s command system.

We can say that an algorithm is a model of the activity of the algorithm executor.

3.1.3. Algorithm properties

Not every instruction, sequence of instructions, or action plan can be considered an algorithm. Each algorithm necessarily has the following properties: discreteness, understandability, certainty, effectiveness and mass character.

The property of discreteness means that the path to solving a problem is divided into separate steps (actions). Each action has a corresponding instruction (command). Only after executing one command can the executor begin executing the next command.

The property of understandability means that the algorithm consists only of commands included in the system of commands of the performer, i.e., of such commands that the performer can perceive and according to which he can perform the required actions.

The property of certainty means that the algorithm does not contain commands whose meaning can be interpreted ambiguously by the performer; Situations are unacceptable when, after executing the next command, it is unclear to the performer which command to execute at the next step.

The efficiency property means that the algorithm must be able to obtain a result after a finite, possibly very large, number of steps. In this case, the result is considered not only the answer determined by the statement of the problem, but also the conclusion about the impossibility of continuing to solve this problem for any reason.

The property of mass production means that the algorithm must provide the possibility of its application to solve any problem from a certain class of problems. For example, the algorithm for finding the roots of a quadratic equation should be applicable to any quadratic equation, the algorithm for crossing the street should be applicable anywhere on the street, the algorithm for preparing medicine should be applicable to preparing any quantity of it, etc.

Example 8. Let's consider one of the methods for finding all prime numbers not exceeding n. This method is called the “sieve of Eratosthenes”, named after the ancient Greek scientist Eratosthenes who proposed it.

To find all prime numbers not greater than a given number n, following the method of Eratosthenes, you need to perform the following steps:

  1. write down all the integers from 2 to n in a row (2, 3, 4, ..., n);
  2. frame 2 - the first prime number;
  3. cross out from the list all numbers divisible by the last prime number found;
  4. find the first unmarked number (marked numbers are crossed out numbers or numbers enclosed in a frame) and enclose it in a frame - this will be another prime number;
  5. repeat steps 3 and 4 until there are no unmarked numbers left.

You can get a more visual idea of ​​the method of finding prime numbers using the animation “The Sieve of Eratosthenes” (http://school-collection.edu.ru/).

The considered sequence of actions is an algorithm, since it satisfies the following properties:

  • discreteness - the process of finding prime numbers is divided into steps;
  • understandability - each command is understandable to a 9th grade student performing this algorithm;
  • certainty - each command is interpreted and executed by the performer unambiguously; there are instructions on the order of execution of commands;
  • effectiveness - after a certain number of steps the result is achieved;
  • mass character - the sequence of actions is applicable for any natural n.

The considered properties of the algorithm allow us to give a more precise definition of the algorithm.

3.1.4. Possibility of automation of human activities

Developing an algorithm is usually a labor-intensive task that requires a person to have deep knowledge, ingenuity and a lot of time.

Solving a problem using a ready-made algorithm only requires the performer to strictly follow the given instructions.

Example 9. From a pile containing any number of objects greater than three, two players take turns taking one or two objects each. The winner is the one who can pick up all the remaining items on his next move.

Let's consider an algorithm, following which the first player will certainly ensure a win.

  1. If the number of objects in the pile is a multiple of 3, then give way to the opponent, otherwise start the game.
  2. With your next move, each time add the number of objects taken by your opponent to 3 (the number of remaining objects must be a multiple of 3).

The performer may not delve into the meaning of what he is doing and not reason why he acts this way and not otherwise, that is, he can act formally. The ability of the performer to act formally provides the possibility of automating human activity. For this:

  1. the process of solving a problem is presented as a sequence of simple operations;
  2. a machine is created ( automatic device), capable of performing these operations in the sequence specified in the algorithm;
  3. a person is freed from routine activities, the execution of the algorithm is entrusted to an automatic device.

The most important

Performer - some object (person, animal, technical device), capable of executing a specific set of commands. A formal performer always performs the same command in the same way. For each formal performer, you can specify: the range of tasks to be solved, the environment, the command system and the operating mode.

An algorithm is a description of a sequence of actions intended for a specific performer that leads from initial data to the required result, which has the properties of discreteness, understandability, certainty, effectiveness and mass character.

The ability of the performer to act formally provides the possibility of automating human activity.

Questions and tasks

  1. What is an algorithm called?
  2. Find synonyms for the word “prescription”.
  3. Give examples of algorithms you studied in school.
  4. Who can be the executor of the algorithm?
  5. Give an example of a formal performer. Give an example when a person acts as a formal performer.
  6. What commands should a robot perform the functions of: a) a cashier in a store; b) a janitor; c) a security guard?
  7. What determines the range of tasks performed by the “computer” performer?
  8. Consider as a performer word processor, available on your computer. Describe the range of tasks solved by this performer and his environment.
  9. What is a team, a system of performer commands?
  10. List the main properties of the algorithm.
  11. What can the absence of any property in an algorithm lead to? Give examples.
  12. Why is it important to be able to formally execute an algorithm?
  13. The sequence of numbers is constructed according to the following algorithm: the first two numbers of the sequence are taken equal to 1; Each next number in the sequence is taken to be equal to the sum of the two previous numbers. Write down the first 10 terms of this sequence.
  14. Some algorithm obtains a new chain from one string of characters as follows. First, the original chain of characters is written, after it the original chain of characters is written in reverse order, then the letter that follows in the Russian alphabet after the letter that was in last place in the original chain is written. If the last place in the original chain is the letter Z, then the letter A is written as the next letter. The resulting chain is the result of the algorithm. For example, if the original chain of characters was DOM, then the result of the algorithm will be the chain DOMMODN. The character string COM is given. How many letters O will there be in the chain of symbols that will be obtained if you apply the algorithm to this chain, and then apply the algorithm again to the result of its work?
  15. Find an animation of the steps of Eratosthenes' algorithm on the Internet. Use Eratosthenes' algorithm to find all prime numbers not exceeding 50.
  16. What will be the result of Turtle’s execution (see example 5) of the algorithm?
      Repeat 8 [Right 45 Forward 45]
  17. Write down an algorithm for the Calculator executor (example 6), containing no more than 5 commands:
      a) receiving from the number 3 the number 16;
      b) receiving from the number 1 the number 25.
  18. The system of executor commands The constructor consists of two commands, which are assigned numbers:
      1 - assign 2
      2 - divide by 2

    According to the first of them, 2 is added to the number on the right, according to the second, the number is divided by 2. How will the number 8 be converted if the performer executes algorithm 22212? Create an algorithm in the command system of this executor, according to which the number 1 will be converted into the number 16 (the algorithm should contain no more than 5 commands).

  19. In which cell should the Robot performer (example 7) be located in order to return to it after executing algorithm 3241?

| § 2.1. Algorithms and executors

Lesson 14
§ 2.1. Algorithms and executors

Keywords:

Algorithm
properties of the algorithm (discreteness; understandability; certainty; effectiveness; mass character)
executor
characteristics of the performer (range of tasks to be solved; environment; operating mode; command system)
formal execution of the algorithm

2.1.1. Algorithm concept

Every person in everyday life, in study or at work solves a huge number of problems of varying complexity. Complex problems require a lot of thought to find a solution; A person solves simple and familiar tasks without thinking, automatically. In most cases, the solution to each problem can be divided into simple stages (steps). For many of these tasks (installing software, assembling a cabinet, creating a website, operating a technical device, buying an air ticket via the Internet, etc.), step-by-step instructions have already been developed and are offered, the sequential implementation of which can lead to the desired result.

Example 1. The problem “Find the arithmetic mean of two numbers” is solved in three steps:

1) think of two numbers;
2) add two planned numbers;
3) divide the resulting amount by 2.

Example 2. The task “Deposit money into your phone account” is divided into the following steps:

1) go to the payment terminal;
2) choose a telecom operator;
3) enter a phone number;
4) check the entered number is correct;
5) insert a banknote into the bill acceptor;
6) wait for a message about money being credited to your account;
7) receive a check.

Example 3. The stages of solving the problem “Draw a funny hedgehog” are presented graphically:


Finding the arithmetic mean, depositing money into a telephone account and drawing a hedgehog are, at first glance, completely different processes. But they have a common feature: each of these processes is described by a sequence of brief instructions, the strict adherence to which allows you to obtain the required result. The sequences of instructions given in examples 1-3 are algorithms for solving the corresponding problems. The executor of these algorithms is a person.

The algorithm can be a description of a certain sequence of calculations (example 1) or steps of a non-mathematical nature (examples 2-3). But in any case, before its development, the initial conditions (initial data) and what is to be obtained (result) must be clearly defined. We can say that an algorithm is a description of the sequence of steps in solving a problem, leading from the initial data to the required result.

In general, the algorithm’s operation diagram can be represented as follows (Fig. 2.1).

Rice. 2.1. General scheme of the algorithm

Algorithms are the rules of addition, subtraction, multiplication and division of numbers studied in school, many grammatical rules, rules of geometric constructions, etc.

Animations “Working with an algorithm” (193576), “Greatest common divisor” (170363), “Least common multiple” (170390) will help you remember some algorithms studied in Russian language and mathematics lessons (http://sc.edu.ru /).

Example 4. Some algorithm leads to the fact that from one chain of characters a new chain is obtained as follows:

1. The length (in characters) of the original string of characters is calculated.
2. If the length of the original chain is odd, then the number 1 is added to the original chain on the right, otherwise the chain does not change.
3. The symbols are swapped in pairs (the first with the second, the third with the fourth, the fifth with the sixth, etc.).
4. The number 2 is added to the right of the resulting chain.

The resulting chain is the result of the algorithm.

So, if the initial chain was A#B, then the result of the algorithm will be the chain #A1B2, and if the initial chain was ABC@, then the result of the algorithm will be the chain BA@B2.

2.1.2. Algorithm executor

Each algorithm is designed for a specific performer.

An executor is an object (person, animal, technical device) capable of executing a certain set of commands.

Distinguish formal and informal performers. A formal performer always performs the same command in the same way. An informal executor can carry out a command in different ways.

Let us consider in more detail the set of formal performers. Formal performers are extremely diverse, but for each of them the following characteristics can be specified: the range of tasks to be solved (purpose), environment, command system and mode of operation.

Range of tasks to be solved. Each performer is created to solve a certain range of problems - constructing chains of symbols, performing calculations, constructing drawings on a plane, etc.

Artist Environment. The area, setting, conditions in which the performer operates are usually called the environment of the given performer. The source data and results of any algorithm always belong to the environment of the performer for whom the algorithm is intended.

Executor command system. An instruction to a performer to perform a separate completed action is called a command. The set of all commands that can be executed by some executor forms the system of commands for this executor (SKI). The algorithm is compiled taking into account the capabilities of a specific performer, in other words, in the system of commands of the performer who will execute it.

Performer operating modes. For most performers, direct control and program control modes are provided. In the first case, the performer waits for commands from a person and immediately executes each received command. In the second case, the performer is first given a complete sequence of commands (program), and then he executes all these commands automatically. A number of performers work only in one of the named modes.

Let's look at examples of performers.

Example 5. Performer The turtle moves on the computer screen, leaving a trace in the form of a line.

The Turtle command system consists of the following commands:

1. Forward n (where n is an integer) - causes the Turtle to move n steps in the direction of movement - in the direction in which its head and body are facing;
2. Right m (where m is an integer) - causes a change in the direction of the Turtle's movement by t degrees clockwise.
Record Repeat k [<Команда1> <Команда2> ... <Командаn>] means that the sequence of commands in brackets will be repeated k times.

Think about what figure will appear on the screen after the Turtle completes the following algorithm.
Repeat 12 [Right 45 Forward 20 Right 45]

Example 6. The system of executor commands The computer consists of two commands, which are assigned numbers:

1 - subtract 1
2 - multiply by 3

The first of them decreases the number by 1, the second increases the number by 3 times. When writing algorithms, for brevity, only command numbers are indicated. For example, algorithm 21212 means the following sequence of commands:

Multiply by 3
subtract 1
multiply by 3
subtract 1
multiply by 3

Using this algorithm, the number 1 will be converted to 15:

((1 3 - 1) 3 - 1) 3 = 15.

Example 7. Performer Robot operates on a checkered field, between adjacent cells there may be walls. The robot moves along the cells of the field and can perform the following commands, which are assigned numbers:


1 - up
2 - down
3 - right
4 - left

When performing each such command, the Robot moves to an adjacent cell in the indicated direction. If there is a wall in this direction between the cells, then the Robot is destroyed.

What will happen to the Robot if it executes the sequence of commands 32323 (here the numbers indicate command numbers), starting to move from cell A? What sequence of commands should the Robot execute in order to move from cell A to cell B without collapsing when it hits the walls?

When developing an algorithm:

1) the objects appearing in the problem are identified, the properties of the objects, the relationships between the objects and possible actions with the objects are established;
2) the initial data and the required result are determined;
3) the sequence of actions of the performer is determined, ensuring the transition from the initial data to the result;
4) the sequence of actions is recorded using commands included in the performer’s command system.

We can say that an algorithm is a model of the activity of the algorithm executor.

2.1.3. Algorithm properties

Not every instruction, sequence of instructions, or action plan can be considered an algorithm. Each algorithm necessarily has the following properties: discreteness, understandability, certainty, effectiveness and mass character.

Discrete property means that the path to solving a problem is divided into separate steps (actions). Each action has a corresponding instruction (command). Only after executing one command can the executor begin executing the next command.

Understandability property means that the algorithm consists only of commands included in the system of commands of the performer, i.e., of such commands that the performer can perceive and according to which he can perform the required actions.

Property of certainty means that the algorithm does not contain commands whose meaning can be interpreted ambiguously by the performer; Situations are unacceptable when, after executing the next command, it is unclear to the performer which command to execute next. Thanks to this, the result of the algorithm is uniquely determined by the set of initial data: if the algorithm is applied several times to the same set of initial data, then the output always produces the same result.

Performance property means that the algorithm must provide a result after a finite, possibly very large, number of steps. In this case, the result is considered not only the answer determined by the statement of the problem, but also the conclusion about the impossibility of continuing to solve this problem for any reason.

Property of mass character means that the algorithm must provide the possibility of its application to solve any problem from a certain class of problems. For example, the algorithm for finding the roots of a quadratic equation should be applicable to any quadratic equation, the algorithm for crossing the street should be applicable anywhere on the street, the algorithm for preparing medicine should be applicable to preparing any quantity of it, etc.

Example 8. Let's consider one of the methods for finding all prime numbers not exceeding some natural number n. This method is called the “sieve of Eratosthenes” after the ancient Greek scientist Eratosthenes (3rd century BC) who proposed it.

To find all prime numbers not greater than a given number n, following the method of Eratosthenes, you need to perform the following steps:

1) write down in a row all the natural numbers from 2 to n (2, 3, 4, ..., n);
2) frame 2 - the first prime number;
3) cross out from the list all numbers divisible by the last prime number found;
4) find the first unmarked number (marked numbers are crossed out numbers or numbers enclosed in a frame) and enclose it in a frame - this will be another prime number;
5) repeat steps 3 and 4 until there are no unmarked numbers left.

You can get a more visual idea of ​​the method of finding prime numbers using the animation “Sieve of Eratosthenes” (180279) posted in the Unified Collection of Digital Educational Resources.

The considered sequence of actions is an algorithm, since it satisfies the following properties:

discreteness- the process of finding prime numbers is divided into steps;
understandability- each command is understandable to an 8th grade student performing this algorithm;
certainty- each command is interpreted and executed by the performer unambiguously; there are instructions on the order of execution of commands;
effectiveness- after a certain number of steps the result is achieved;
mass character- the sequence of actions is applicable for any natural number n.

The considered properties of the algorithm allow us to give a more precise definition of the algorithm.

An algorithm is a description of a sequence of actions intended for a specific performer that leads from initial data to the required result, which has the properties of discreteness, understandability, certainty, effectiveness and mass character.

2.1.4. Possibility of automation of human activities

Developing an algorithm is usually a labor-intensive task that requires a person to have deep knowledge, ingenuity and a lot of time.

Solving a problem using a ready-made algorithm only requires the performer to strictly follow the given instructions.

Example 9. From a pile containing any number of objects greater than three, two players take turns taking one or two objects each. The winner is the one who can pick up all the remaining items on his next move.

Let's consider an algorithm, following which the first player will certainly ensure a win.

1. If the number of objects in the pile is a multiple of 3, then give way to the opponent, otherwise start the game by taking 1 or 2 objects so that the number of objects remaining is a multiple of 3.
2. With your next move, each time add the number of objects taken by your opponent to 3 (the number of remaining objects must be a multiple of 3).

The performer may not delve into the meaning of what he is doing and not reason why he acts this way and not otherwise, that is, he can act formally. The ability of the performer to act formally provides the possibility of automating human activity. For this:

1) the process of solving a problem is presented as a sequence of simple operations;
2) a machine (automatic device) is created that is capable of performing these operations in the sequence specified in the algorithm;
3) a person is freed from routine activities, the execution of the algorithm is entrusted to an automatic device.

THE MOST IMPORTANT

Executor- some object (person, animal, technical device) capable of executing a certain set of commands.

A formal performer always performs the same command in the same way. For each formal executor you can specify: range of tasks to be solved, environment, command system and operating mode.

Algorithm- a description of the sequence of actions intended for a specific performer that leads from the initial data to the required result, which has the properties of discreteness, understandability, certainty, effectiveness and mass character.

Performer's ability to act formally provides the ability to automate human activities.

Questions and tasks

1. Read the presentation materials for the paragraph contained in electronic application to the textbook. Does the presentation complement the information contained in the text of the paragraph? What slides could you add to your presentation?

2. What is called an algorithm?

3. Choose synonyms for the word “prescription”.

4. Give examples of algorithms you studied in school.

5. Who can be the executor of the algorithm?

6. Give an example of a formal performer. Give an example when a person acts as a formal performer.

7. What determines the range of tasks performed by the “computer” performer?

8. Consider the word processor on your computer as the executor. Describe the range of tasks solved by this performer and his environment.

9. What is a team, a system of performer commands?

10. What commands should a robot perform the following functions:

a) cashier in a store;
b) a janitor;
c) a security guard?

11. List the main properties of the algorithm.

12. What can the absence of any property in an algorithm lead to? Give examples.

13. What is the importance of being able to formally execute an algorithm?

14. The sequence of numbers is constructed according to the following algorithm: the first two numbers of the sequence are taken equal to 1; Each next number in the sequence is taken to be equal to the sum of the two previous numbers. Write down the first 10 terms of this sequence. Find out what this sequence is called.

15. A certain algorithm obtains a new chain from one string of characters as follows. First, the original chain of characters is written, after it the original chain of characters is written in reverse order, then the letter that follows in the Russian alphabet after the letter that was in last place in the original chain is written. If the letter “I” is in the last place in the original chain, then the letter “A” is written as the next letter. The resulting chain is the result of the algorithm. For example, if the original chain of characters was “HOUSE”, then the result of the algorithm will be the chain “DOMMODN”. The character string “COM” is given. How many letters “O” will there be in the chain of characters that will be obtained if you apply the algorithm to this chain, and then apply the algorithm again to the result of its work?

16. Find an animation of the steps of Eratosthenes’ algorithm on the Internet. Use Eratosthenes' algorithm to find all prime numbers not exceeding 50.

17. What will be the result of Turtle’s execution (see example 5) of the algorithm?

18. Write down an algorithm for the Calculator executor (see example 6), containing no more than 5 commands:

a) receiving from the number 3 the number 16;
b) receiving from the number 1 the number 25.

19. System of performer commands The constructor consists of two commands, which are assigned numbers:

1 - assign 2
2 - divide by 2

According to the first of them, 2 is added to the number on the right, according to the second, the number is divided by 2. How will the number 8 be converted if the performer executes algorithm 22212? Create an algorithm in the command system of this executor, according to which the number 1 will be converted into the number 16 (the algorithm should contain no more than 5 commands).

20. In which cell should the Robot performer (example 7) be located in order to return to it after executing algorithm 3241?

Free Software:

KuMir system - Set of educational worlds (download the program archive from the website) or visit the KuMir page ((http://www.niisi.ru/kumir/)

Please suspend AdBlock on this site.

In this lesson we will look at 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 begin with, I suggest you play a little with the following children's toy. Complete 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 several basic concepts:

  • executor;
  • system of performer commands;
  • algorithm.

In the toy we control a red bird. The goal 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 carry out some commands is called an executor. In this toy, obviously, the performer is a bird. The set of commands that the performer understands and can execute is called system of executor commands.

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

It is necessary to focus on several points.

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

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

You can write down the available commands in any order that you consider correct. Your task as a programmer is to divide a large complex task into small individual steps, each of which will be understandable to the performer. The principle of “divide and conquer” is at work again.

The performer does exactly what the algorithm tells him to do.

The bird performer is very trusting. She doesn't question what you write in the program. If, for example, you forget to turn the bird, it will crash into the wall. Therefore, you must monitor everything yourself.

Your future programs will often not work as you intended. Mistakes happen to everyone. Here it is important to understand that it is not the computer that is stupid, but you made a mistake in the algorithm. Don't be like bad programmers, for whom the program is always to blame for everything.

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

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

So, to summarize:

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 a performer 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.

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

Algorithm– an accurate and understandable instruction to the performer to execute the final sequence of commands leading from the initial data to the initial result.

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

Algorithm executor– this is the one who executes the algorithm (person, animal, machine, computer).

Executor command system- this is the entire set of commands that the performer knows how to perform (understands). The algorithm can be built only from commands included in the system of executor commands.

For example, performer The robot can perform commands forward, backward, left, right, paint. It moves across a cell field bounded by a wall and containing walls. The robot cannot go through the wall.

Algorithm properties:

1.Performance (limb)– the ability to obtain a result from the initial data in a finite number of steps. (For example, when executing the algorithm for adding 2 numbers, the sum should be obtained).

2.Mass character– the ability to apply the algorithm to a large number of different source data. (For example, You can add any 2 numbers, knowing the addition algorithm.)

3.Determinism(certainty, accuracy) – each command must uniquely determine the action of the performer.

4.Understandability– the command must be written in a language understandable to the computer.

5.Discreteness– splitting the algorithm into separate commands.

Ways to write the algorithm:

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

2) Graphic – in the language of flowcharts, using geometric shapes (oval, rectangle, parallelogram, rhombus).

3) In an algorithmic language - a language for writing algorithms for teaching programming. Commands 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. Breaking tasks down into subtasks. Auxiliary algorithms.

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

Basic algorithmic constructions are linear sequence of steps (or following), branching and looping.

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

This is what a linear algorithm looks like in block diagram language:

Example: algorithm for turning on the computer:

  1. Turn on the computer power (press the button on surge protector).
  2. Turn on the monitor and printer.
  3. Click Power button on system unit.
  4. Wait for loading operating system and the appearance of the Desktop.
  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 the 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 the condition, two numbers, two strings, two variables or string expressions are compared with each other using comparison operators (>,<, =, >=, <=).

Recording in algorithmic language: IfCondition Then Series 1 (If Condition true, then true Episode 1, If Condition false, then nothing is executed). Example: If today is Sunday, then there is no need to go to school. Full form of branching

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

There are two types of cyclic algorithmic structures:

  • countered loops, in which the body of the loop is executed a certain number of times;
  • conditional loops, in which the body of the loop is executed as long as the condition is satisfied.

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

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 executor- this is the object or subject for which the algorithm is designed to control.

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

Properties of the algorithm: understandability, accuracy, finiteness.

Clarity: the algorithm is composed only of commands included in the executor’s SKI.

Accuracy: Each command of the control algorithm determines the unambiguous action of the performer.

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

Performer's environment: the environment in which the performer operates.

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

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

Methods for writing algorithms.

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

Graphic method involves the use of certain graphic symbols - blocks.

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

The collection of blocks forms the so-called algorithm flowchart.

Verbal recording algorithms are focused primarily on the human performer and allow for different recording of instructions, but the recording must be quite accurate.

When writing algorithms in the form programs computers use programming languages ​​- systems for encoding instructions and rules for their use. Writing algorithms in the form of programs is characterized by a high degree of formalization.

Algorithms for working with quantities. Basic algorithmic structures.

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

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

Quantities can be constant or 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 value can change the value during the execution of the algorithm. A variable is always designated by a symbolic name (X, A, R5, etc.).

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

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

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

An assignment command is an executor's 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 receive after executing the command: A:= 2 * A - 1?
Solution. Calculating the expression 2*A - 1 with A=6 will give the number 11. This means the new value of the variable A will be equal to 11.

In what follows it will be assumed that the performer 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 variable values ​​are set through input devices (for example, a keyboard).

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

Output command: A command that displays the value of a quantity on a computer output device (such as a monitor).

Example: conclusion X - the value of the X variable 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 general continuation. Branching can be complete or incomplete. Description of branching in block diagrams and in Algorithmic language:

Here, a series means one or more sequential commands; kv - end of branching.

Loop command ensures repeated execution of a sequence of commands (loop body) based on some condition.

Loop with precondition- a loop whose execution is repeated until the loop condition 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. Two simple fractions are given. Create an algorithm for obtaining a fraction that is the result of their division.
Solution. In algebraic form, the solution to the problem looks like this:
a/b: c/d = a*d/b*c = m/n
The initial data are four integer quantities: a, b, c, d. The result is two integers m and n.

alg dividing fractions
intact 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 output text (any character sequence), it must be written in quotes in the command conclusion.

  1. Efimova O., Morozov V., Ugrinovich N. Course in computer technology with the basics of computer science. Tutorial for high school. - M.: LLC "AST Publishing House"; ABF, 2000
  2. Problem book-workshop in computer science. In 2 volumes/Ed. I. Semakina, E. Henner. - M.: Laboratory of Basic Knowledge, 2001.
  3. Ugrinovich N. Computer Science and information Technology. 10-11 grades - M.: Laboratory of Basic Knowledge, JSC "Moscow Textbooks", 2001

Tasks and tests on the topic "Algorithms and executors"

  • Artist Management Draftsman - Algorithms 6th grade

    Lessons: 4 Assignments: 9 Tests: 1

  • 2 Tasks: 9 Tests: 1

Dear student!

Knowledge of the Topic "Algorithms and Executors" is necessary primarily for further study of programming. The QBasic programming language was chosen as the basis for studying programming. We abandoned the idea of ​​including Visual Basic or any other object-oriented programming language in our course, since this approach has not yet been widely used in most secondary schools in the Russian Federation. In addition, object-oriented programming is based on the principles of classical Dos programming.

Our course is designed for the general education program. When preparing for entrance exams in information technology to universities, you need to familiarize yourself with the specifics of studying programming at a given university. In some cases, an in-depth study of a number of topics is necessary, for example, "Arrays". You should pay attention to this when studying programming literature; perhaps you should use methodological recommendations on preparation for exams, which are currently published in most higher education institutions.

In conclusion, we note that achieving “aerobatics” in programming is possible only with constant practice and solving specific applied problems.




Top