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
- Number of ways to split a binary number such that every part is divisible by 2
- Number of times the largest perfect square number can be subtracted from N
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- 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
- Given number of matches played, find number of teams in tournament
- Count number of ways to divide a number in 4 parts
- Querying maximum number of divisors that a number in a given range has
- Build Lowest Number by Removing n digits from a given number
- Super Ugly Number (Number whose prime factors are in given set)
- Find the smallest number whose digits multiply to a given number n
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.