B8 · Computational Thinking and the AI Project Cycle

Decision Trees

A decision tree is a diagram that reaches a decision by asking a series of questions. It starts with one question at the top, called the root; each answer leads down a branch to another question; and the ends of the branches, called leaves, give the final decisions. In AI, decision trees can be learned automatically from examples.

10 min Beginner Jump to the activity

What you need: Nothing. This page starts from the beginning, with no programming and no formulas.

Definition

A doctor asks: "Do you have a fever? Is your throat sore? For how many days?" Each answer leads to the next question, until a decision is reached. That chain of questions has a shape: a tree.

A decision tree is a diagram that reaches a decision by asking a series of questions. It starts with one question at the top, called the root; each answer leads down a branch to another question; and the ends of the branches, called leaves, give the final decisions. In AI, decision trees can be learned automatically from examples.

In simple words

Playing "twenty questions" is a decision tree. "Is it an animal?" Yes. "Does it live in water?" No. "Is it bigger than a dog?" Yes… Each answer cuts down the possibilities until only one is left.

Why it matters

Decision trees are one of the easiest kinds of AI model to understand, because you can read exactly which questions led to a decision. They are used in medicine, banking and farming, and they show clearly how a machine can learn rules from data.

Key terms

Decision tree
A tree of yes-or-no questions leading to decisions.
Root
The first question, at the top of the tree.
Branch
A path from a question to the next step, for one answer.
Node
Any point in the tree where a question is asked.
Leaf
An end point that gives a final decision or label.
Depth
The number of questions from the root to the deepest leaf.

Explained in detail

Reading a decision tree

Imagine a tree that decides whether to play cricket outside. The root asks: "Is it raining?" If yes, the leaf says "stay in". If no, the next question is "Is it hotter than 40 °C?" If yes, "stay in". If no, "Is the ground free?" If yes, "play"; if no, "stay in". To use the tree, you start at the root and follow the branches matching your situation until you reach a leaf. You can always explain the decision by reading the path: "We played because it was not raining, not too hot and the ground was free."

How a machine learns a tree

A person can draw a tree from their own knowledge, but a computer can also learn one from examples. Suppose you have records of 100 past days: the weather, the temperature, whether the ground was free, and whether cricket was played. The computer tries each possible question and picks the one that best splits the days into "played" and "did not play" groups. Then it repeats inside each group, picking the best next question, until the groups are pure enough or the tree is deep enough. The result is a set of rules learned from data, not written by hand.

Real uses

FieldExample questionsDecision
Health screeningFever? Cough longer than two weeks? Weight loss?Refer for a tuberculosis test or not
FarmingLeaf spots? Yellow edges? Recent heavy rain?Likely disease and treatment
BankingRegular income? Past loans repaid? Amount requested?Approve, review or decline
Customer helpIs it about a payment? A delivery? A refund?Which team should answer

Strengths and weaknesses

  • Strength: easy to read and explain, which matters when decisions affect people.
  • Strength: works with categories (yes/no, colours) as well as numbers.
  • Weakness: a very deep tree can memorise its examples and do badly on new cases.
  • Weakness: if the examples are biased, the learned questions will be too.

In practice, many AI systems combine hundreds of small decision trees, each trained a little differently, and let them vote. This approach, called a random forest, is usually more accurate than any single tree, though harder to explain.

How it works

  1. Decide what the tree should decide, such as "play or stay in".
  2. Choose the most useful first question for the root.
  3. For each answer, add the next question or a final decision.
  4. Make sure every path ends in a leaf.
  5. Test it on examples you did not use to build it.

Try it yourself

A tree that sorts fruit

A fruit seller wants a quick way to sort mangoes, bananas and oranges on a conveyor belt.

Follow the tree

A day: no rain, 32 °C, ground free. Put the steps of using the cricket tree in order.

  1. 1Leaf: play
  2. 2Root: is it raining? No
  3. 3Is the ground free? Yes
  4. 4Is it hotter than 40 °C? No

Common mistakes

  • Leaving a branch with no leaf at the end.
  • Building a tree so deep that it memorises the examples.
  • Forgetting that a learned tree copies any bias in its examples.

Check yourself

Question 1

1. What is a leaf in a decision tree?

Question 2

2. Why are decision trees easy to explain?

Question 3

3. How does a computer choose the root question when learning a tree?

Summary

  • A decision tree asks questions from root to leaf to reach a decision.
  • Computers can learn trees from examples by choosing the best splitting questions.
  • Trees are easy to explain but can memorise or copy bias.

Finished reading?

Sources: Elements of AI (University of Helsinki) · CBSE Artificial Intelligence curriculum resources