left= left= left= am am and and iteration= am and am and and egg am iteration= and and and if am egg and iteration= am and if am if and the egg iteration= am and if am the and two if iteration= and and if am two the iteration= and and two iteration= and left= left= if if egg egg egg if if the egg if if if egg the if two if if egg two if left= left= the the two two the two the two two figure computation of the optimal binary search tree for sample input figure shows the table that will be produced by the algorithm for each subrange of wordsthe cost and root of the optimal binary search tree are maintained the bottommost entry computes the optimal binary search tree for the entire set of words in the input the optimal tree is the third tree shown in figure the precise computation for the optimal binary search tree for particular subrangenamelyam ifis shown in figure it is obtained by computing the minimum-cost tree obtained by placing amandeggand if at the root for instancewhen and is placed at the rootthe left subtree contains am am (of cost via previous calculation)the right subtree contains egg if (of cost )and pam pand pegg pif for total cost of the running time of this algorithm is ( )because when it is implementedwe obtain triple loop an ( algorithm for the problem is sketched in the exercises all-pairs shortest path our third and final dynamic programming application is an algorithm to compute shortest weighted paths between every pair of points in directed graphg (vein we saw an algorithm for the single-source shortest-path problemwhich finds the shortest path from some arbitrary vertexsto all others that algorithm (dijkstra'sruns in (| | time on dense graphsbut substantially faster on sparse graphs we will give short algorithm to solve the all-pairs problem for dense graphs the running time of the algorithm is (| | )which is not an asymptotic improvement over |viterations of dijkstra' algorithm but could be faster on very dense graphbecause its loops are tighter the algorithm also