dimanche 10 janvier 2016

Print random element from binary tree in O(logn)

Given a binary tree with TreeNode like:

class TreeNode {
    int data;
    TreeNode left;
    TreeNode right;
    int size;
}

Where size is the number of nodes in the (left subtree + right subtree + 1).

Print a random element from the tree in O(logn) running time.




Aucun commentaire:

Enregistrer un commentaire