25
Branching algorithm
Textbook: pp. 66–68
GoalKnow what a branching algorithm is: the action depends on a condition (if ... then we do ...).
New words
if · agarcondition · shartbranching · tarmoqlanishdecision · qaror
Explanation
In life we often decide according to the situation. If it is cold outside, we put on a warm jacket. If it is warm, no jacket is needed. An algorithm whose actions depend on a condition is called a branching algorithm. In words we write it with “if”: “If yes — do this, if no — do that”.
Worked examples
At a traffic light: if the green light is on, we cross; otherwise we stop and wait.
If a number divides by 2 it is even, if not it is odd. 8 is even, 9 is odd.
Class activity
“If it is true”: the teacher states a condition and children act. “If your clothes are blue, stand up. If not, clap.” Each child does just one action, depending on the condition.
Practice
1
Algorithm: if a number divides by 2 it is even, otherwise odd. What kind of number is 14?
even
2
By the same algorithm, what kind of number is 17?
odd
3
Finish the sentence “If it rains — ...”
Free answer (I take an umbrella)