Which algorithm is called the repetition algorithm. Algorithm with repetition

In algorithms, commands are written one after another in a certain order.

Linear Algorithms

An algorithm in which commands are executed in the order they are written, that is, sequentially one after another, is called linear.

For example, the following tree planting algorithm is linear (Fig. 58):

  1. dig a hole in the ground;
  2. lower the seedling into the hole;
  3. fill the hole with the seedling with earth;
  4. water the seedling.

Rice. 58

With the help of a block diagram, this algorithm can be depicted as follows (Fig. 59).

Rice. 59

Branching Algorithms

In life, you often have to make a decision depending on the current situation. If it rains, we take an umbrella and put on a raincoat; If it's hot, wear light clothing. There are also more complex selection conditions. In some cases, the fate of a person depends on the chosen decision.

The decision logic can be described as follows:

    IF THEN ELSE

Example:

    IF you want to be healthy, then temper yourself, ELSE lie all day on the couch.

    May be missing in some cases: IF THEN

Example:

    IF he called himself a loader, THEN climb into the back.

The form of organization of actions in which, depending on the fulfillment or non-fulfillment of a certain condition, either one or another sequence of actions is performed is called branching.

Let's depict in the form of a flowchart the sequence of actions of the 6th grade student Vasya Mukhin, which he imagines as follows: “If Pavlik is at home, we will solve problems in mathematics. Otherwise, you should call Marina and prepare a report on biology together. If Marina is not at home, then you need to sit down to compose ”(Fig. 60).

Rice. 60

And so, with the help of a flowchart, you can very clearly present the reasoning when solving the following problem (Fig. 61).

Rice. 61

Of the three coins of the same denomination, one is counterfeit (lighter). How to find it with the help of one weighing on a pan balance without weights?

Algorithms with repetitions

In practice, there are often tasks in which one or more actions may need to be repeated several times until some predetermined condition is met.

The form of organization of actions in which the execution of the same sequence of actions is repeated until some predetermined condition is met is called cycle(by repetition). An algorithm containing loops is called cyclical algorithm or repetition algorithm.

The situation in which the execution of the loop never ends is called looping. Algorithms should be developed to avoid such situations.

Consider an example from life. This is how a flowchart of the actions of a schoolboy who should do his homework in mathematics before an evening walk may look like this (Fig. 62).

Rice. 62

This round robin. When it is executed, the "Solve the problem" action will be performed as many times as the number of tasks contains the student's homework.

Center for organizing and holding International and All-Russian distance competitions of the official website "PRIDE OF RUSSIA!" (2015-2016)

APPLICATION FOR PARTICIPATION IN THE EXPRESS COMPETITION

FOR TEACHERS

Position: primary school teacher

Abbreviated name of educational institution: MBOU secondary school No. 5

Shelter location: Pyt-Yakh

Email: [email protected].ru

Nomination: My best lesson

Title of work: lesson "Algorithm with repetition"

Competition format (International, All-Russian): All-Russian competition

Number of diplomas: 1

Payment details (detailed): online

View document content
"Lesson Summary"

teacher MBOU "Secondary School No. 5, Pyt-Yakh

Tyumen region

Abstract of a mathematics lesson on the topic "Algorithms with repetition (cycle)". Program 2100

Target:

To consolidate the idea of ​​​​the algorithm, algorithm scheme, types of algorithms

Introduce the algorithm with repetition (loop)

To consolidate the ability to compose and execute linear and non-linear algorithms, write and read algorithm schemes using conventional signs.

Tasks:

1. Subject: introduce a new kind of algorithms, understand the notation of algorithms, compose linear and non-linear algorithms (with branches and loops)

a) cognitive UUD:

Development of attention, thinking, visual memory of students;

Extract knowledge from various sources (text, figures, diagrams, symbols);

The ability to navigate in your knowledge system: to distinguish the new from the already known;

b) communicative UUD:

To teach children to control their speech (build a coherent answer) when expressing their point of view on a given topic;

Develop the ability to express their thoughts and prove their point of view;

Interact with each other (listen to compare and evaluate the answers of others)

c) regulatory UUD:

Make a plan for solving a learning problem;

- plan the sequence of steps of the algorithm to achieve the goal;

3. Personal:

Formation of the ability of reflective self-esteem, the ability to analyze one's actions, manage them

To instill in students the skills of communication and cooperation, based on ethical standards, to respect the opinions of others.

Equipment:

textbook "Mathematics" (authors T.E. Demidova, S.A. Kozlova, A.P. Tonkikh), multimedia presentation, projector, handout.

1.Org. moment.

Commented record of the number and type of work. Slide

2. Updating knowledge

Let's start our lesson with a crossword puzzle. Slide

What is an algorithm?

(Algorithm- sequence, order of actions of the performer to achieve the result)

What is the algorithm?

(from steps that are called commands)

Name the forms of writing algorithms.

(verbal, flowcharts) Slide

What is used to write block diagrams? (geometric shapes) Slide

Our lesson is a lesson-journey. But where we will go - you will find out by performing the actions according to the given algorithm.

Using this program actions, find the valuesXand write them down in a table. Arrange the answers in descending order and unscramble the word.

Z K S A K A



On a normal day, at the appointed hour

I invite you to fairy tales!

Algorithms will accompany us in fairy tales.

What kind of algorithm was used in this task?

In fairy tales, as in life, there are also algorithms.

And in order to open these gates to a fairy tale, we need to create an algorithm for opening doors.

Make an algorithm for opening the door with a key.

(on sheets in pairs) against the background of music

What kind of algorithm was used in this task? (linear)

Well, since we have a math lesson, we will perform mathematical algorithms.

3. Creation of a problem situation.

And here is the magical apple orchard in which you need to pick apples.

We need to make an algorithm of our actions. Slide

We put one apple in the basket, but there is more than one apple on it. How to continue our algorithm?

Our actions are repeated. What is the name of such an algorithm?

(algorithm with repetition)

Are there any in mathematics?

Define an iterative algorithm.

4. Application of new knowledge

Continuing our lesson, we will learn to apply new knowledge

b) Work in groups

Algorithm 1. Design the work of Cinderella from the fairy tale "Cinderella" in the form of an algorithm

After the wedding, the stepmother immediately showed her evil temper. She was well aware that next to a beautiful, kind-hearted stepdaughter, her own daughters look even uglier and uglier. Therefore, she hated her stepdaughter and forced her to do all the most difficult and dirty work around the house.

So she made Cinderella sort all the collected beans into two different baskets: a white one into an oval one, and a red one into a round one.

And the Stepdaughter could not go to bed until she had done all the work.

Algorithm 2. Arrange in the form of an algorithm the choice of the bride by the prince from the fairy tale "Cinderella".

The next day, the prince announced that he would marry the girl who would fit the glass slipper. Princesses, duchesses and court ladies all came to the palace. The prince met every girl, tried on a shoe for them. But when I saw that the shoe did not fit, I said goodbye to them. The Cinderella sisters also tried on the shoe, but to no avail. Then Cinderella asked:

Can I try too?

Her sisters laughed. But the prince said:

I will try on the shoe for all the girls without exception.

The slipper was freely put on Cinderella's foot, as if it had been made from it. Immediately, Cinderella took out a second shoe from her pocket, and everyone froze in amazement.

Checking group work. Algorithm Protection Slides

5. Homework.

Visiting fairy tales is good, but home is better.

Open your diaries, write down your homework. S. 85 No. 5, 6.

On an A4 sheet, write down a verbal and appropriate algorithm (indicate its type) for performing any work and arrange your work (having shown creative abilities).

6. Reflection. Summary of the lesson. Slide

“The tale is a lie, but there is a hint in it - a lesson for good fellows!” And what lesson did fairy tales teach us today?

What new did we learn in the lesson? (answer)

– What have you learned?

Today we made algorithms for the plots of fairy tales. But do situations happen in life when we act according to the algorithm? Give examples

Who has had a hard time so far?

Who or what helped you cope?

Who is happy with their work today?

Who would like to fix it? What? What do I need to do?

What mark would you give yourself?

I had no doubt that all of you know and love fairy tales, each of you will receive an assessment for practical work, and I would like to note the most active participants in the lesson (grades are given).

View presentation content
"Lesson Presentation"


Presentation for the lesson "Visiting a fairy tale with algorithms"


The purpose of the lesson:

  • consolidate the idea of ​​the algorithm, algorithm scheme, types of algorithms
  • introduce the algorithm with repetition (cycle)
  • to consolidate the ability to compose and execute linear and non-linear algorithms, write and read algorithm schemes using conventional signs.

Lesson objectives:

1. Subject: introduce a new kind of algorithms, understand the notation of algorithms, compose linear and non-linear algorithms (with branches and loops)

a) cognitive UUD:

-development of attention, thinking, visual memory of students;

- extract knowledge from various sources (text, drawings, diagrams, symbols);

- the ability to navigate in your knowledge system: to distinguish the new from the already known; at

b) communicative UUD:

To teach children to control their speech (build a coherent answer) when expressing their point of view on a given topic;

- develop the ability to express their thoughts and prove their point of view;

- interact with each other (listen to compare and evaluate the answers of others)

c) regulatory UUD:

- make a plan for solving a learning problem;

- plan the sequence of steps of the algorithm to achieve the goal;

3. Personal:

- formation of the ability of reflective self-assessment, the ability to analyze one's actions, manage them

- to instill in students the skills of communication and cooperation, based on ethical standards, to respect the opinions of others.


Classwork.


ALGORITHM

Algorithm- sequence, order of actions of the performer to achieve the result


  • verbal,
  • block diagram

Figure name

Image

Denoted step of the algorithm

Oval

Rhombus

Rectangle

Beginning and the end

Decision-making

Performing an action


18 +24 -15 x" width="640"

With this program of action,

find the values X and write them down in a table.

Put your answers in order

descending and unscramble the word.

Z K S A K A




Start

Get the key

Insert the key into the keyhole

Turn the key 2 times

Take out the key

the end


Visiting a fairy tale

with algorithms



Harvest

Enter the garden

Come to the apple tree

pick an apple

Put an apple in the basket


Harvest

Enter the garden

Come to the apple tree

pick an apple

Put an apple in the basket

Are there any apples left on the apple tree?

Are there any apple trees left?






Start

meet a girl

Try on her shoes

Say goodbye to a girl

Approached?

Cinderella has been found!

End


Collect grits

Go through the grits

apply water

Clean the boiler

Wash the floor


A fairy tale is a lie, but there is a hint in it

good fellows - a lesson!

There are three types of algorithms - linear, branching, cyclic.

Linear type of algorithms

Algorithms in which instructions are executed one after another, regardless of any conditions, are called linear type algorithms.

For example, an algorithm for calculating the simplest formulas that do not have restrictions on the values ​​of the variables included in them.

Example

Formulation of the problem : Calculate the area of ​​a circle if the radius is known.

Given : R is the radius of the circle.

Find: S is the area of ​​the circle.

Solution: S=3.14R 2

The verbal form of the algorithm

Let's choose the Russian language for writing the algorithm in this form and write down a sequence of commands, the execution of which, with a given radius value, will allow us to find the area:

    Read R value.

    Multiply the R value by 3.14.

    Multiply the result of the second action by the R value.

    Record the result as an S value.

In the language of flowcharts - rice. eight

Branching type of algorithms

Problem solving cannot always be represented as a linear algorithm.

Algorithms in which it is required to organize the choice of a sequence of actions depending on any conditions are called branching type algorithms.

With the graphical method, branching is organized using a logical element (rhombus), which has one input and two outputs. The purpose of the logic element is to check the given condition. Depending on the fulfillment (true) or non-fulfillment (falsehood) of the condition being checked, it is possible to exit, respectively, to the “Yes” or “No” branch.

Example

Formulation of the problem : calculate
.

Given: x is the value of the argument.

Find: y – function value.

Solution:

y= xif x  0

- x if x<0

block diagram - see fig. 9.

verbal representation

On pseudocode :

Read x value

If x>0 then

End of branch

Write value at

Allocate complete and incomplete conditional construction .

Cyclic type of algorithms

When compiling algorithms for solving a sufficiently large range of problems, there often arises a need for repeated repetition of the same commands.

An algorithm compiled using multiple repetitions of the same actions (cycles) is called cyclic algorithms.

However, "repeatedly" does not mean "indefinitely". The organization of loops that never leads to a halt in the execution of the algorithm (the so-called looping) is a violation of the requirement for its effectiveness.

When developing an algorithm for a cyclic structure, the following concepts are distinguished:

    loop parameter – value, the change of which is associated with repeated execution of the cycle;

    start and end value of the parameter cycle ;

    cycle step is the value by which the loop parameter changes on each iteration.

The cyclic algorithm consists of loop preparation, loop body, loop continuation conditions .

V cycle preparation includes actions related to setting the initial values ​​for the cycle parameter (initial and final values, parameter step).

V loop body includes: repetitive actions for calculating the desired values; preparation of the next value of the cycle parameter, preparation of other values ​​necessary for repeated execution of actions in the body of the cycle.

V continuation condition the need for further repetitive actions is determined. If the loop parameter exceeds the end value, then the loop execution must be terminated.

Consider a graphical representation of the cyclic block of the algorithm (see Fig. 10).

Cycles can be precondition(when the condition is checked before the beginning of the loop body) and with postcondition(when the condition is checked after the first iteration of the loop body).

Loop with postcondition

Loop with precondition