// Optimal binary search tree #include #define MAXKEYS (30) int n; // number of keys int key[MAXKEYS+1]; float p[MAXKEYS+1]; // probability of hitting key i float q[MAXKEYS+1]; // probability of missing between key[i-1] and key[i] float c[MAXKEYS+1][MAXKEYS+1]; // cost of subtree int r[MAXKEYS+1][MAXKEYS+1]; // root of subtree float w[MAXKEYS+1][MAXKEYS+1]; // accumulated p and q void opttree() { float x,min; int i,j,k,h,m; int countNoRootTrick=0,countWithRootTrick=0; for (i=0;i<=n;i++) c[i][i]=0; // width of tree h=0 for (i=0;i