Factor Tree is an intuitive method to understand the 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
This article is contributed by Suprotik Dey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count the nodes of the given tree whose weight has X as a factor
- k-th prime factor of a given number
- N-th prime factor of a given number
- Largest factor of a given number which is a perfect square
- Smallest number S such that N is a factor of S factorial or S!
- Find largest prime factor of a number
- Sum of largest prime factor of each number less than equal to n
- Sum of Maximum and Minimum prime factor of every number in the Array
- Greatest odd factor of an even number
- Exactly n distinct prime factor numbers from a to b
- Queries on the sum of prime factor counts in a range
- Nearest element with at-least one common prime factor
- Count of subarrays whose products don't have any repeating prime factor
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count all the numbers less than 10^6 whose minimum prime factor is N
- Prime Factor
- Find largest factor of N such that N/F is less than K
- Count of distinct power of prime factor of N
- Least prime factor of numbers till n
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
Improved By : shubham_singh