Home » Machine Learning/Artificial Intelligence

# Decision Trees in Machine learning

In this article, we are going to learn about the **decision trees in Machine Learning**, where are they used and its advantages over other algorithms.

Submitted by Basantjeet Das, on November 13, 2018

## Decision Trees Algorithm

A **decision tree** is a tree-like structure or graph based on **decisions** and their possible consequences to a situation. In a **decision tree**, every node represents criteria or a parameter, and every branch directs to the outcome, and the leaf nodes depicting the final outcome (class labels).

What **Decision trees** do is, it solves the problems by framing a tree on the basis of **decisions** in a top-down manner from root to the leaf nodes, with each leaf node providing a classification to the problem. Each node corresponds to one of the possible answers to the test case or to another node forwarding to the solutions. For applying decision tree an algorithm should contain conditional statements only.

Decision trees are generally recursive in nature and are performed on every node of the sub-tree.

**Let's take an example for better understanding,**

Suppose we want to play golf on Sunday, but we want to find if it is suitable to play golf on Sunday or not. Before stepping out we chose to check out the weather forecast first like if it's hot or cold, the speed of the wind, humidity, how the weather is, i.e. is it sunny, cloudy, or rainy.

Suppose the weather forecast says that it will be Sunny with no wind and normal humidity.

Undertaking the following factors into account we can predict if its suitable to play or not.

Let us assume we have data of the last 10 days for the above-discussed factors, shown below.

Then on applying the **Decision Trees algorithm**, we can predict that we can play golf on Sunday with the help of the above-discussed factors.

Similarly, **Decision tree** could be used to predict the outcomes of many situations which have data split under various parameters & conditions (both nested and unnested).

### Advantages of Decision Trees over Other Algorithms

- It can be applied to both categorical & numerical data.
- Doesn't need much of Data Pre-processing.
- It can recover from outliers.
- Gives the privilege to add more parameters for better precision and accuracy.
- Can be used significantly large and complex datasets.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions