RFNXVfwQQPS4J

From problem to algorithm

Source: licencja: CC 0.

Od problemu do algorytmu

You will learn
  • to create an algorithm in the form of a command list,

  • the basic principles of creating algorithms,

  • how to talk about it in English.

REZI5nMRJhJWM
nagranie abstraktu

Answer the introductory questions:

  1. What is an algorithmalgorithmalgorithm?

  2. Provide a recipereciperecipe for boiling water in an electric kettle?

  3. Will the recipe for boiling water in the kettle on the stove look the same?

  4. Suggest a recipe for boiling water describing both cases.

RFKbXkk3FQk2c1
nagranie abstraktu

Certainly you have already realized that electronic devices, including computers, tablets or smartphones, work strictly according to the „recipes” developed by people. However, before the programmerprogrammerprogrammer enters the codecodecode into the memory of such a machine, on the basis of which it will perform the tasks assigned to it, it is necessary to carefully analyse what the device should do and in what situation. Seemingly, it seems to be simple, but when we start to create such a recipereciperecipe, which is technically called an algorithmalgorithmalgorithm, it turns out that it is complicated and many situations have to be anticipated.

Let's try to create an algorithm for ... an elevator - a device we often use.

R11Gqe8LfzACW
An elevator
Rt3SPznDrVgd6
nagranie abstraktu

Imagine that the elevator runs only between two floors:

  • ground floor level,

  • first floor level.

Our algorithm in the simplest case will be based on the following commands:

  • go up,

  • go down,

  • stop the elevator,

  • open the door,

  • close the door.

And information:

  • the call button was pressed on the ground floor,

  • the call button was pressed on the first floor,

  • the 'to the ground floor' selection button was pressed in the elevator,

  • the 'to the first floor' selection button was pressed in the elevator.

And the variablevariablevariable 'storey', which will take the valuevaluevalue 'ground floor' if the elevator will be located on the ground floor or 'first floor' when it is on the first floor.

RwwsDIIoSFC7X1
nagranie abstraktu

The simplest algorithmalgorithmalgorithm that would cause a passenger who approaches the elevator on the ground floor to go up, would look like this:

  • if 'the call button was pressed on the ground floor' - open the door,

  • if the 'to the first floor' selection button was pressed in the elevator - close the door,

  • go up,

  • if level equals 'first floor' - stop the elevator,

  • open the door.

RZs629RfktVYD1
nagranie abstraktu

The algorithm is very simple, but we actually assumed that the elevator is downstairs waiting for the passenger, so that does not have to be true.

So it's time for you.

Task 1
R1ET9dVoVGtvk1
nagranie abstraktu

Rewrite the algorithmalgorithmalgorithm so that the elevator works as before, but in addition:

A: first it goes down to the passenger, if it was left upstairs.
B: it serves both passengers going up and down.
C: additionally, it serves the third storey (basement).

Rl0F0ZiOkLxY21
nagranie abstraktu

When you deal with the above tasks, think that the real elevator still:

  • reacts to the 'stop' emergency button,

  • takes passengers on the way from other storeys if they pressed the call button in the direction in which the elevator moves ('up or down'),

  • will not stop 'on the way' if there is already a maximum number of passengers in the elevator.

The commands used by you in the algorithms are written using the graphic symbols shown in the interactive picture.

R1ebDxWBzR9F4
Ilustracja interaktywna przedstawia sześć symboli graficznych, nazywanych blokami. Reprezentują one polecenia wykorzystywane przy tworzeniu algorytmów. 1 - owal, prostokąt z zaokrąglonymi rogami. 2 - prostokąt. 3 - równoległobok. 4 - romb. 5 - prostokąt z dodatkowymi pionowymi kreskami po bokach. 6 - kółko. Wybierz odpowiedni przycisk aby dowiedzieć się jaką funkcje pełnią w schemacie blokowym. Na ilustracji widoczne są numery, a na nich podpisy. 1. The beginning or end of the algorithm. {audio}, 2. The figure represents the process. Inside it, we place all calculations or substitutions. {audio}, 3. Reading or writing data. Inside the figure there are instructions on what to do. {audio}, 4. Decision block. Inside it, we place a condition that can be answered YES or NO. {audio}, 5. A process that has already been defined. {audio}, 6. Page link. We use if we want to move from one place on a page to another. {audio}
The building blocks of flowchart
Source: GroMar, licencja: CC BY 3.0.
RQZKG0UG5hHpi1
nagranie abstraktu

An algorithmalgorithmalgorithm is a procedure that ultimately leads to a specific effect. The algorithm should be correct, finite, effective, unambiguous and universal. It means that it should cover all possible cases describing a given situation. In the end it should always give the correct result after completing the finite number of actions.

Exercises

Exercise 1
RXjBn9Onr6Gak
Wersja alternatywna ćwiczenia: Determine which sentence is true. Możliwe odpowiedzi: 1. You can create an algorithm for solving some mathematical equation., 2. You can create an algorithm for calculating the square area., 3. An algorithm can be used in any situation in real life., 4. A recipe for baking a cake can be an algorithm., 5. An algorithm is only in the graphic version., 6. It’s necessary to know one of the programming languages to write some algorithm.
zadanie
Source: GroMar, licencja: CC BY 3.0.
Exercise 2

Create a garbage sorting algorithm for your house.

Exercise 3

Write in English how to create algorithms.

Exercise 4
RVHJJBNBsTmm9
Wersja alternatywna ćwiczenia: Indicate which pairs of expressions or words are translated correctly. Możliwe odpowiedzi: 1. algorytm - algorithm, 2. instrukcja - instruction, 3. programista - programmer, 4. kod - code, 5. zmienna - value, 6. wartość - variable
zadanie
Source: GroMar, licencja: CC BY 3.0.
R2GVZtaJ7daVK1
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
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
final result
final result

wynik końcowy

R1Tgd5Q2ioUm91
wymowa w języku angielskim: final result
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

algorithmalgorithmalgorithm

codecodecode

instructioninstructioninstruction

programmerprogrammerprogrammer

recipereciperecipe