Given a generic tree, how would you pick a node at random with uniform probability?
Respostas da entrevista
Sigiloso
8 de mar. de 2012
Just pick a number from 1 to N and do an inorder traversal.
2
Sigiloso
20 de out. de 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.