Given a generic tree, how would you pick a node at random with uniform probability?
Interview Answers
Anonymous
Mar 8, 2012
Just pick a number from 1 to N and do an inorder traversal.
2
Anonymous
Oct 20, 2011
Flatten the tree into an array list, then generate a uniform random number from 0 to 1, and choose the corresponding index in the flattened array list.