Given a generic tree, how would you pick a node at random with uniform probability?
Respuestas de entrevistas
Anónimo
8 mar 2012
Just pick a number from 1 to N and do an inorder traversal.
2
Anónimo
20 oct 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.