Class 6 · Unit 3: Patterns and decisions · Lesson 3.4 · 40 min
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.
Today you will: Draw a decision tree for sorting apples · Turn it into if–then–else blocks in Scratch · Try to break a partner's tree
Story
It is harvest time in Shopian. Bilal's uncle has a mountain of apples and three kinds of box:
Box A — big, red, no marks, sent to Delhi. Box B — good apples with small marks, for the local market. Box C — damaged apples, made into juice.
The helpers keep asking, "Which box?" So Uncle draws a picture of questions on a piece of cardboard. Now anyone can sort, even a new helper.
That picture is called a decision tree.
Watch
Asking yes/no questions to decide — — scan code 6.3.4 in the printed book.
Warm up your fingers
- 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.
On the laptop
Tools: LibreOffice Draw · Scratch Desktop (offline, no account)
Mission 1: Draw the tree (pairs, 10 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?
- ☐7
Your turn: add one question you think matters, like
Is it too small?. Where does it go? - ☐8
Save as
apple-tree.odg.
Mission 2: Make it work (pairs, 12 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.
Now you know
- A decision tree is a chain of yes/no questions that leads to a decision.
- Branches and leaves: each question splits into branches; the final answers are the leaves.
- In code, each question is an if-then-else: if it's true do one thing, else do another.
- Order matters. Asking the most important question first (damaged?) saves time.
- Some AI builds its own trees by learning from lots of examples.
🕌 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).
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
1. What does a decision tree use to reach a decision?
- ○ Random guesses
- ○ A series of yes/no questions
- ○ A photograph
- ○ Only numbers
2. Match each part to its meaning:
Branch · Leaf · Question
Match with: the final decision · the point where the tree splits · the path an answer sends you down3. In Scratch, a yes/no decision is made with the ______ block.
4. Some AI programs can build decision trees by themselves from examples.
- ○ True
- ○ False
Remember
A decision tree asks yes/no questions, one after another, until it reaches a decision.