binary tree is called ancestral if each node has either 0 or 2 child nodes. Let N be the number of different ancestral trees there are with 2015 nodes. Find the last three digits of N .
A
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Yes, that's the formula for a full binary tree.
Can we find the last 3 digits without a computer?
Hint: Consider ( 1 0 0 7 2 0 1 4 ) ( m o d 1 0 0 0 × 1 0 0 8 ) .
All ancestral trees have an odd number of nodes. A tree with 2 n + 1 nodes consists of a top node, and continues with trees of sizes 2 k + 1 and 2 k ′ + 1 . We have k + k ′ = n − 1 .
The numbers get large quickly! Therefore I truncate all values modulo 1000. After all, we only need the last three digits. This code gives the correct answer of 4 8 0 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Simple python:
l=[0,1]
for i in range(2,2016):
s=0
for j in range(1,i):
s+=l[j]*l[i-1-j]
l.append(s%1000)
print(l[2015])
Problem Loading...
Note Loading...
Set Loading...
Such ancestral binary tree is normally called a full binary tree. It is well-known that the number of full binary trees with 2 n + 1 vertices is C n , where C n is the n -th Catalan number given as n + 1 1 ( n 2 n ) . (One simple proof is to consider the sizes of the subtrees of the root, and compare it with the identity C n + 1 = ∑ i = 0 n C i C n − i .) Simply plugging this in, we want to find the last three digits of C 1 0 0 7 = 1 0 0 8 1 ( 1 0 0 7 2 0 1 4 ) ; with some language that supports arbitrary precision integer (like Java or Python), we can compute that this 602-digit number ends with 4 8 0 .