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.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store