algorithm design techniques /*compute optimal ordering of matrix multiplication contains the number of columns for each of the matrices is the number of rows in matrix the minimum number of multiplications is left in ] actual ordering is computed via another procedure using lastchange and lastchange are indexed starting at instead of noteentries below main diagonals of and lastchange are meaningless and uninitialized *void optmatrixconst vector cmatrix mmatrix lastchange int size forint left left < ++left mleft ]left forint ++ / is right left forint left left < ++left /for each position int right left kmleft ]right infinityforint lefti right++ int thiscost mleft ] mi ]right cleft ci cright ]ifthiscost mleft ]right /update min mleft ]right thiscostlastchangeleft ]right ifigure program to find optimal ordering of matrix multiplications the problem is to arrange these words in binary search tree in way that minimizes the expected total access time in binary search treethe number of comparisons needed to access an element at depth is so if wi is placed at depth di then we want to minimize = pi ( di as an examplefigure shows seven words along with their probability of occurrence in some context figure shows three possible binary search trees their searching costs are shown in figure