Factor Tree is an intuitive method to understand factors of a number. It shows how all the factors are been derived from the number. It is a special diagram where you find the factors of a number, then the factors of those numbers, etc until you can’t factor anymore. The ends are all the prime factors of the original number.
Input : v = 48 Output : Root of below tree 48 / 2 24 / 2 12 / 2 6 / 2 3
The factor tree is created recursively. A binary tree is used.
- We start with a number and find the minimum divisor possible.
- Then, we divide the parent number by the minimum divisor.
- We store both the divisor and quotient as two children of the parent number.
- Both the children are sent into function recursively.
- If a divisor less than half the number is not found, two children are stored as NULL.
Level order traversal of constructed factor tree 48 2 24 2 12 2 6 2 3
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.