Decision Trees & Ensembles Questions with Answers

8 practice questions on Decision Trees & Ensembles (AI & Machine Learning) with answers and step-by-step solutions. Try 8 samples below, then practise all 8 free in the AptiNest app.

Sample questions

Question 1Easy

Which is a common way to prevent a decision tree from overfitting?

  1. Growing the tree until every leaf is pure
  2. Using every feature at every split
  3. Removing the root node after training so that the tree has fewer levels
  4. Limiting the maximum depth or pruning the tree

Answer: D. Limiting the maximum depth or pruning the tree

Explanation

Constraints such as max_depth, min_samples_leaf, or cost-complexity pruning stop the tree from memorising noise.

Step-by-step solution

  1. An unrestricted tree keeps splitting until leaves are pure.
  2. That memorises noise in the training data.
  3. Limiting depth, requiring a minimum number of samples per leaf, or pruning keeps it simpler.

Why the other options are wrong

  • A. Growing to pure leaves is what causes overfitting.
  • B. Using every feature does not limit complexity.
  • C. Removing the root destroys the tree; it is not a valid technique.

Question 2Easy

What is the entropy of a node containing 50% positive and 50% negative examples (log base 2)?

  1. 2
  2. 1
  3. 0.5
  4. 0

Answer: B. 1

Explanation

Entropy = -0.5 log2 0.5 - 0.5 log2 0.5 =
0.5 + 0.5 = 1, the maximum for two classes. A pure node has entropy 0.

Step-by-step solution

  1. Entropy H = -sum p log2 p.
  2. p = 0.5 for each class: H = -(0.5 x -1 + 0.5 x -1).
  3. H = 1 bit.

Why the other options are wrong

  • A. Two-class entropy is at most 1 bit.
  • C. 0.5 is the maximum Gini impurity, not entropy.
  • D. Entropy is 0 only for a pure node.

Tip: Two classes: 50/50 gives entropy 1 and Gini 0.5.

Question 3Medium

A node has 4 samples: 1 of class A and 3 of class B. What is its Gini impurity?

  1. 0.25
  2. 0.375
  3. 0.75
  4. 0.5

Answer: B. 0.375

Explanation

Gini = 1 - (p_A^2 + p_B^2) = 1 - (0.25^2 + 0.75^2) =
1 - (0.0625 + 0.5625) = 0.375.

Step-by-step solution

  1. Gini = 1 - sum of p squared.
  2. p(A) = 1/4, p(B) = 3/4.
  3. Gini = 1 - (1/16 + 9/16) = 6/16 = 0.375.

Why the other options are wrong

  • A. 0.25 is p(A), not the impurity.
  • C. 0.75 is p(B).
  • D. 0.5 is the Gini of a 50/50 node.

Tip: Two classes: Gini = 2p(1 - p) = 2 x 0.25 x 0.75 = 0.375.

Question 4Medium

How does boosting (e.g. AdaBoost or gradient boosting) differ from bagging?

  1. It uses only one model
  2. Models are trained independently in parallel on bootstrap samples
  3. Models are trained in sequence, each fixing earlier errors
  4. It always uses neural networks as base learners

Answer: C. Models are trained in sequence, each fixing earlier errors

Explanation

Boosting mainly reduces bias by adding weak learners that correct residual errors; bagging mainly reduces variance.

Step-by-step solution

  1. Bagging trains models independently, in parallel, on bootstrap samples.
  2. Boosting trains models one after another.
  3. Each new model focuses on the errors of the ones before it.

Why the other options are wrong

  • A. Both are ensembles of many models.
  • B. This describes bagging, not boosting.
  • D. Boosting usually uses small decision trees, not neural networks.

Tip: Bagging = parallel + average; boosting = sequential + correct.

Question 5Medium

Random Forest reduces overfitting compared with a single decision tree mainly by:

  1. Training trees sequentially on previous errors
  2. Pruning every tree to depth 1 so that each one is too simple to overfit
  3. Using only linear decision boundaries
  4. Averaging many trees built on bootstrap samples and random features

Answer: D. Averaging many trees built on bootstrap samples and random features

Explanation

Bagging plus random feature selection decorrelates the trees, so averaging them reduces variance.

Step-by-step solution

  1. Each tree trains on a bootstrap sample (rows drawn with replacement).
  2. Each split considers only a random subset of features.
  3. Averaging many decorrelated trees cancels out their individual errors and lowers variance.

Why the other options are wrong

  • A. Sequential training on errors is boosting.
  • B. Random forests usually grow deep trees, not stumps.
  • C. Trees give axis-aligned, non-linear boundaries.

Question 6Medium

Which statement about decision trees is true?

  1. They do not require feature scaling
  2. They cannot handle categorical features in principle
  3. They always produce linear decision boundaries
  4. They can only be used for classification

Answer: A. They do not require feature scaling

Explanation

Splits compare a single feature with a threshold, so rescaling a feature does not change the tree. Trees also do regression (CART) and give axis-aligned, non-linear boundaries.

Step-by-step solution

  1. Trees split on thresholds such as 'age > 30'.
  2. Rescaling a feature changes the threshold value but not which rows go left or right.
  3. So scaling does not affect a tree.

Why the other options are wrong

  • B. Trees can split on categories directly in principle.
  • C. Tree boundaries are piecewise, axis-aligned and non-linear.
  • D. Regression trees predict numbers too.

Tip: Trees and forests: no scaling needed.

Question 7Hard

In a Random Forest, what is the out-of-bag (OOB) error?

  1. Error on a separate test set supplied by the user
  2. Error on training rows left out of each tree's bootstrap sample
  3. Training error of the deepest tree in the forest, measured on its own bootstrap sample
  4. Error caused by features missing from the dataset

Answer: B. Error on training rows left out of each tree's bootstrap sample

Explanation

Each bootstrap sample leaves out about 37% of the rows; predicting them with the trees that did not see them gives a built-in validation estimate.

Step-by-step solution

  1. Each bootstrap sample leaves out about a third of the rows.
  2. Those out-of-bag rows are predicted only by trees that did not see them.
  3. The error on these predictions estimates test error without a separate set.

Why the other options are wrong

  • A. OOB error needs no user-supplied test set.
  • C. A tree's error on its own bootstrap sample is training error.
  • D. OOB has nothing to do with missing features.

Tip: OOB is about 37% of rows per tree: a built-in validation set.

Question 8Hard

A node has 6 positive and 4 negative samples (entropy 0.971). A split produces a left child with 4 positive, 0 negative and a right child with 2 positive, 4 negative (entropy 0.918). What is the information gain of the split?

  1. 0.05
  2. 0.42
  3. 0.97
  4. 0.55

Answer: B. 0.42

Explanation

Weighted child entropy =
(4/10) x 0 + (6/10) x 0.918 = 0.551.
Information gain =
0.971 - 0.551 = 0.42.

Step-by-step solution

  1. Left child (4+, 0-) is pure: entropy 0, weight 4/10.
  2. Right child (2+, 4-) has entropy 0.918, weight 6/10.
  3. Weighted child entropy = 0.6 x 0.918 = 0.551.
  4. Gain = 0.971 - 0.551 = 0.42.

Why the other options are wrong

  • A. 0.05 comes from subtracting the unweighted right entropy (0.971 - 0.918).
  • C. 0.97 is the parent entropy, not the gain.
  • D. 0.55 is the weighted child entropy, not the gain.

Practise all 8 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all AI & Machine Learning topics · All topics