The Nth term in the Wedderburn–Etherington number sequence (starting with the number 0 for n = 0) counts the number of unordered rooted trees with n leaves in which all nodes including the root have either zero or exactly two children.
For a given N. The task is to find first N terms of the sequence.
0, 1, 1, 1, 2, 3, 6, 11, 23, 46, 98, 207, 451, 983, 2179, 4850, 10905, 24631, 56011, ….
Trees with 0 or 2 childs:
Input : N = 10
Output : 0, 1, 1, 1, 2, 3, 6, 11, 23, 46,
Input : N = 20
Output : 0, 1, 1, 1, 2, 3, 6, 11, 23, 46, 98, 207, 451, 983, 2179, 4850, 10905, 24631, 56011, 127912
The Recurrence relation to find Nth number is:
- a(2x-1) = a(1) * a(2x-2) + a(2) * a(2x-3) + … + a(x-1) * a(x)
- a(2x) = a(1) * a(2x-1) + a(2) * a(2x-2) + … + a(x-1) * a(x+1) + a(x) * (a(x)+1)/2
Using the above relation we can find the ith term of the series. We will start from the 0th term and then store the answer in a map and then use the values in the map to find the i+1 th term of the series. we will also use base cases for the 0th, 1st and 2nd element which are 0, 1, 1 respectively.
Below is the implementation of the above approach :
0, 1, 1, 1, 2, 3, 6, 11, 23, 46
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count number of triplets with product equal to given number with duplicates allowed
- Find minimum number to be divided to make a number a perfect square
- Total number of possible Binary Search Trees using Catalan Number
- Number of ways to divide a given number as a set of integers in decreasing order
- Number of times the largest perfect square number can be subtracted from N
- Given number of matches played, find number of teams in tournament
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Check if a number is divisible by all prime divisors of another number
- Build Lowest Number by Removing n digits from a given number
- Find the smallest number whose digits multiply to a given number n
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Program to Convert Octal Number to Binary Number
- Number of digits to be removed to make a number divisible by 3
- Check whether all the rotations of a given number is greater than or equal to the given number or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.