treeNode selectNode(treeNode root, MTRandom clustererRandom) {

        //random number between 0 and 1
        double random = clustererRandom.nextDouble();

        while (!isLeaf(root)) {
            if (root.lc.cost == 0 && root.rc.cost == 0) {
                if (root.lc.n == 0) {
                    root = root.rc;
                } else if (root.rc.n == 0) {
                    root = root.lc;
                } else if (random < 0.5) {
                    random = clustererRandom.nextDouble();
                    root = root.lc;
                } else {
                    random = clustererRandom.nextDouble();
                    root = root.rc;
                }
            } else {

                if (random < root.lc.cost / root.cost) {

                    root = root.lc;
                } else {

                    root = root.rc;
                }
            }
        }

        return root;
    }