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 triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
- Find minimum number to be divided to make a number a perfect square
- Largest number dividing maximum number of elements in the array
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Smallest number dividing minimum number of elements in the array | Set 2
- Number of ways to divide a given number as a set of integers in decreasing order
- Smallest number dividing minimum number of elements in the Array
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Total number of possible Binary Search Trees using Catalan Number
- Given number of matches played, find number of teams in tournament
- Number of times the largest perfect square number can be subtracted from N
- Number of ways to split a binary number such that every part is divisible by 2
- Find the largest good number in the divisors of given number N
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
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.