void compute (int n, double[][] A, double[][] B, double[][] C)
{
for (int i=1; i <= n; i++) {
for (int j=1; j <= n; j++) {
int p = i, q = i;
while ( (p < n) && (q < n) ) {
A[i][j] += B[p][q] + C[p][q];
p *= 2;
q *= 2;
}
}
}
}
Recall that an ordinary binary tree can become highly imbalanced. For this purpose, several sophisticated trees (like AVL or red-black) have been devised. At the same time, also recall that simple randomization (as we did in randomly picking the partition element in Quicksort) is also effective. So, one approach to improving binary trees is to introduce some randomization. We'll define a random-label (RL) tree to be a binary tree with the following additional features:

After the remaining insertions, we get:

Submission: