Decision trees — sorting apples
A mountain of apples, three boxes, and helpers who keep asking "which box?" Uncle draws his answer on a piece of cardboard.
- Draw a decision tree for sorting apples
- Turn it into if–then–else blocks in Scratch
- Try to break a partner's tree
Decision trees — sorting apples
A mountain of apples, three boxes, and helpers who keep asking "which box?" Uncle draws his answer on a piece of cardboard.
- Draw a decision tree for sorting apples
- Turn it into if–then–else blocks in Scratch
- Try to break a partner's tree
Story
Learn it
Uncle's cardboard is a decision tree: a chain of yes/no questions where each answer sends you to the next question, until you reach a decision. A new helper does not need thirty years of experience; they just follow the questions. Computers love decision trees, because every question becomes one if–then–else in code.
Words to know
a chain of yes/no questions that leads to a decision.
a point where the tree splits in two, one way for yes and one for no.
the path an answer sends you down.
the end of a branch: the final decision.
the code version of one question: if it is true, do one thing; else (if not), do another. In Scratch it is a block.
Step by step: a tree for "what do I wear?"
- First question: Is it snowing? Yes → wear the pheran. That branch ends in a leaf.
- No → ask the next question: Is it raining? Yes → take the umbrella (a leaf).
- No → wear the school jacket (a leaf).
- Check it: every path ends in a leaf, so the tree has an answer for every day.
The same tree in code:
if snowing then
wear pheran
else
if raining then take umbrella
else wear jacket
Order matters. Ask the most important question first. Uncle asks "Is it damaged?" before anything else, because a damaged apple goes to juice whatever its size or colour.
Some AI builds its own trees by learning from lots of examples, choosing the questions that sort the examples best.
🕌 From our heritage
This shape of thinking is old. Scholars of uṣūl al-fiqh — the principles by which Islamic legal rulings are worked out — reason through an ordered chain of questions, where each answer decides which question comes next, until the chain reaches a ruling. Different schools may order the questions differently and reach different rulings, which is why the order of the questions matters as much as the questions themselves. Your apple tree works the same way.
The method is set out in works of uṣūl al-fiqh, such as al-Ghazālī's al-Mustaṣfā (11th century).
Careful: there is not only one right tree. Many trees can sort the same things correctly, and the best one asks the fewest questions. In Scratch, you write the questions; only some AI programs build their own tree from examples.
Your missions
Tools: LibreOffice Draw · Scratch Desktop (offline, no account)
Draw the tree
pairs10 min- 1
Open LibreOffice Draw. Draw a box at the top:
Is it damaged? - 2
Draw two arrows below it, labelled Yes and No.
- 3
Under Yes, draw a box:
Box C (juice). - 4
Under No, draw another question:
Is it big and red? - 5
Add Yes → Box A (Delhi) and No → Box B (local market).
- 6
Predict: if you add one more question, will the tree still sort every apple?
Only you can see this - 7
Your turn: add one question you think matters, like
Is it too small?. Where does it go? - 8
Save as
apple-tree.odg.
Make it work
pairs12 min- 9
Open Scratch Desktop. Choose any sprite.
- 10
Sensing → ask [ ] and wait:
Is the apple damaged? (yes/no) - 11
Control → if ⟨ ⟩ then … else. In the diamond, put Operators → ⟨ (answer) = yes ⟩.
- 12
In then: Looks → say [Box C (juice)].
- 13
In else: ask
Is it big and red?with another if-then-else inside. - 14
Click the green flag and test different answers. Does every path end in a box?
- 15
Swap laptops with a partner and try to break their tree. Find an apple it sorts wrongly.
No laptop today?
Draw the tree on paper with arrows. Then act it out: one student is the tree and asks only the yes/no questions; the others describe an imaginary apple and walk to the right "box" corner of the room.
Debate it
A factory uses a decision tree to sort apples, and the tree says small apples always go to juice. One farmer grows a special small variety that is sweet and valuable.
Is the tree fair to that farmer? Who should be able to change the tree?
Check yourself · practice, not a test
In the app, students answer these one at a time and each answer is checked straight away. It's practice, never a mark — anything they miss comes back later for another go.
1.What does a decision tree use to reach a decision?
- ARandom guesses
- BA series of yes/no questions
- CA photograph
- DOnly numbers
2.Match each part to its meaning:
- Branch
- Leaf
- Question
- the final decision
- the point where the tree splits
- the path an answer sends you down
3.In Scratch, a yes/no decision is made with the ______ block.
4.Some AI programs can build decision trees by themselves from examples.
TrueFalse
A decision tree asks yes/no questions, one after another, until it reaches a decision.
Typing practice
- On typing.com: your next Beginner lesson.
- Practise Shift for capital letters today, because you will type box names like Box A.
- Remember: the opposite hand presses Shift.
Written and designed by Faizan Ayoub. © 2026 Faizan Ayoub. All rights reserved.