Interview question
Surprisingly good interview question on recursion:
- Write a function that outputs a binary tree of N nodes having a random structure. Node values don’t matter; the function must return any possible binary tree of N nodes with non-zero probability.
- Extra question: write a function counting the total number of different binary trees composed of N nodes and having different structure.
And technically the same problem set, but defined in such a way it’s a bit trickier to approach it:
- Write a function that outputs a binary tree of N nodes having a random structure. Node values don’t matter; the function must return any possible binary tree of N nodes with equal probability.