RFNXVfwQQPS4J

Consolidating exercises

Source: licencja: CC 0.

Zadania utrwalające

You will learn
  • to analyze simple algorithms and present them in the form of a list of commands,

  • the basic principles of creating algorithms,

  • how to talk about it in English.

RISNZXk8tgGNP1
nagranie abstraktu

First, try to solve the puzzle:

The villager has to transport a wolf, a goat and a cabbage across the river. The boat, however, is so small that only a villager and one of the three can fit into it. If he leaves the wolf with the goat, the wolf will devour the goat. If he leaves the goat with the cabbage, the goat will eat the cabbage. How can a villager handle the transport?

Write down the recipereciperecipe to solve this puzzle.

Hint

Pokaż więcej

Task 1
RNdUG4BmaOI6T1
nagranie abstraktu

Follow the instructions written:

  1. Place the pencil on the card.

  2. Repeat 4 times.
    2.1. Repeat 4 times.
    2.1.1. Move by 10 cm.
    2.1.2. Turn right 90 degrees.
    2.2. Turn right 90 degrees.

Was the algorithmalgorithm algorithm written precisely? What is the final result of the task?

Task 2
RAz7HJ1uPyv6m1
nagranie abstraktu

Write an algorithm for changing units from ms to kmh and conversely.

Task 3
Rq3cQwiNUdtYr1
nagranie abstraktu

Write an algorithm for determining the body weight depending on its mass and the planet on which the body is located.

Task 4
RfIXBcPFvkO6T1
nagranie abstraktu

Write an algorithmalgorithm algorithm for vacuuming the apartment. In the algorithm, consider that the vacuum cleaner has a very short power cord.

Task 5
RuO3PibvlC6D3
nagranie abstraktu

Draw a flowchartflowchartflowchart for the recipereciperecipe for cooking boiled eggs.

  1. Put the egg in boiling water.

  2. Note the initial time tIndeks dolny 0

  3. Read the current time t.

  4. Calculate Δt = t - tIndeks dolny 0

  5. If Δt <3 min., go to step 3.

  6. Remove the egg from the boiling water.

  7. End the algorithm.

Modify the commandcommandcommand depending on if you want to cook either boiled egg or soft‑boiled egg. The soft boiled egg is boiled for less than 3 minutes.

Task 6
R1CLuqkJJ4HbQ1
nagranie abstraktu

Analyse the algorithmalgorithm algorithm below and list the consecutive steps that are being implemented. Specify the problem that the indicated algorithm applies to.

R1EEUMJEk7BaW
The algorithm
Source: GroMar, licencja: CC BY 3.0.
Task 7
RrhAfFqDfCGwx1
nagranie abstraktu

Analyse the interactive picture and see what steps are performed during the implementation of the algorithm when finding the largest common divisor.

R1H1G0s5mPlUn
Ilustracja interaktywna przedstawia schemat blokowy algorytmu Euklidesa, służący do znalezienia największego wspólnego dzielnika. Na rysunku znajdują się bloki oznaczone numerami od 1 do 6. Na górze owal z napisem START. Strzałka w dół prowadzi do równoległoboku oznaczonego cyfrą 1, z napisem Enter numbers A and B. Strzałka w dół prowadzi do rombu oznaczonego cyfrą 2, z napisem A different from B? Strzałka wychodząca w prawo i w dół podpisana YES prowadzi do rombu oznaczonego cyfrą 3, z napisem A > B ? Strzałka w lewo i w dół podpisana NO prowadzi do prostokąta oznaczonego cyfrą 4, z napisem B=B-A. Od rombu 3 strzałka w prawo i w dół podpisana YES prowadzi do prostokąta oznaczonego cyfrą 5, z napisem A=A-B. Od obu prostokątów oznaczonych 4 i 5 strzałki prowadzą ponownie do rombu oznaczonego 2. Z rombu oznaczonego 2 wychodząca strzałka w lewo i w dół podpisana NO prowadzi do równoległoboku z napisem Display "A". Od równoległoboku strzałka e dół prowadzi do owalu oznaczonego liczbą 6, z napisem END. Na ilustracji widoczne są numery, a na nich podpisy. 1. Enter the numbers A and B. {audio}, 2. Check if the numbers A and B are equal. If so, the number A which is the same as the number B is the least common denominator, if not go to 3. {audio}, 3. Check which number is greater. Depending on the answer, perform actions 4 or 5. {audio}, 4. For the number B substitute the differences between the numbers B and A and retry the commands starting from 2. {audio}, 5. For the number A substitute the differences between the numbers A and B and retry the commands starting from 2. {audio}, 6. End. {audio}
The Euclidean algorithm
Source: GroMar, licencja: CC BY 3.0.
R1N9QpVnROyaa1
nagranie abstraktu

When we have a problem, it's best to create a recipereciperecipe for solving it. The recipe is in our case an algorithm. To write it correctly, let's analyse the stages of its creation and writing:

  1. formulating the problem,

  2. specifying the type of input data,

  3. determining the result and the way how it is presented,

  4. determining the method of performing the task,

  5. writing the algorithmalgorithm algorithm using the chosen method,

  6. analysis of the correctness of the solution,

  7. testing the solution for various data.

RrFXCp7GsydzJ
nagranie abstraktu

Ways of writing the algorithm:

  1. list of subsequent commands,

  2. pseudo‑language (pseudocode),

  3. graphical presentation using a flowchartflowchartflowchart,

  4. writing in a given programming language.

The creation of the algorithm forces us to analyse all possible (or at least known to us) cases. By using an algorithmic approach, you can avoid unpleasant surprises in many cases.

Exercises

Exercise 1
R1XuTD5Ag9Y3a
Wersja alternatywna ćwiczenia: Which sentence is true? Możliwe odpowiedzi: 1. The diamond symbol in the flowchart symbolizes the command to display the result on the screen., 2. The diamond symbol in the flowchart symbolizes the condition selection command., 3. It’s possible to mark three options, not only YES/NO, at the same place in the flowchart., 4. The graphic algorithm has to start from the start symbol., 5. The graphic algorithm can be long., 6. Every algorithm is optimized (the best possible).
zadanie
Source: GroMar, licencja: CC BY 3.0.
Exercise 2

Write the algorithm you need to use to calculate the area of geometric figures you know.

Exercise 3

Write in English a few tips to follow in order to create a good algorithm.

Exercise 4
R19AThJMNDBHw
Wersja alternatywna ćwiczenia: Indicate which pairs of expressions or words are translated correctly. Możliwe odpowiedzi: 1. algorytm - algorithm, 2. programista - programmer, 3. przepis - recipe, 4. polecenie - command, 5. zmienna - value, 6. wartość - variable
zadanie
Source: GroMar, licencja: CC BY 3.0.
RlJpnT7IA8IYY1
Interaktywna gra, polegająca na łączeniu wyrazów w pary w ciągu jednej minuty. Czas zaczyna upływać wraz z rozpoczęciem gry. Jeden ruch to odkrywanie najpierw jednej potem drugiej karty z wyrazem. Każdy wyraz jest odczytywany. Kolejny ruch to odkrywanie trzeciej i czwartej karty. W ten sposób odsłuchasz wszystkie wyrazy. Nawigacja z poziomu klawiatury za pomocą strzałek, odsłuchiwanie wyrazów enterem lub spacją. Znajdź wszystkie pary wyrazów.
Source: Zespół autorski Politechniki Łódzkiej, licencja: CC BY 3.0.

Glossary

algorithm
algorithm

algorytm

RgH5syagLTXeE1
wymowa w języku angielskim: algorithm
flowchart
flowchart

schemat blokowy

RXI09wVADB2tx
wymowa w języku angielskim: flowchart
code
code

kod

R1JorZ2D5ClUr1
wymowa w języku angielskim: code
command
command

polecenie

RjncVhVx1BA7L1
wymowa w języku angielskim: command
constant
constant

stała

RzEPgfwX9ZtAR1
wymowa w języku angielskim: constant
instruction
instruction

instrukcja

RyCCuvEkuAYh81
wymowa w języku angielskim: instruction
programmer
programmer

programista

R1YBSnOoEIops1
wymowa w języku angielskim: programmer
recipe
recipe

przepis

R1PGNtrm1bwLD1
wymowa w języku angielskim: recipe
value
value

wartość

RkcOiDV89Jt0V1
wymowa w języku angielskim: value
variable
variable

zmienna

RCBeE3UIqQDMk1
wymowa w języku angielskim: variable

Keywords

algorithmalgorithm algorithm

codecodecode

instructioninstructioninstruction

programmerprogrammerprogrammer

recipereciperecipe