tailieunhanh - ALGORITHMS phần 10

thể đạt được bằng cách nhân một thông qua C theo cách tối ưu, sau đó nhân D thông qua F theo cách tối ưu, sau đó nhân các ma trận kết quả với nhau. (Chỉ có D là thực sự trong mảng tốt nhất: tối ưu chia tách được chỉ định bởi các cặp của các chữ cái trong bảng cho rõ ràng) | DYNAMIC PROGRAMMING 489 be achieved by multiplying A through C in the optimal way then multiplying D through F in the optimal way then multiplying the resulting matrices together. Only D is actually in the best array the optimal splits are indicated by pairs of letters in the table for clarity. To find how to multiply A through C in the optimal way we look in row A and column C etc. The following program implements this process of extracting the optimal parenthesization from the cost and best arrays computed by the program above procedure order i j integer begin if i j then write name i else begin write order i best 1 j 1 write order best i j j write end end For our example the parenthesization computed is A B C D E F which as mentioned above requires only 36 scalar multiplications. For the example cited earlier with the dimensions of 3in B C and F changed to 300 the same parenthesization is optimal requiring 2412 scalar multiplications. The triple loop in the dynamic programming code leads to a running time proportional to and the space required is proportional to substantially more than we used for the knapsack problem. But this is quite palatable compared to the alternative of trying all N tĩN possibilities. Optimal Binary Search Trees In many applications of searching it is known that the search keys may occur with widely varying frequency. For example a program which checks the spelling of words in English text is likely to look up words like and and the far more often than words like dynamic and programming. Similarly a Pascal compiler is likely to see keywords like end and do far more often than label or downto. If binary tree searching is used it is clearly advantageous to have the most frequently sought keys near the top of the tree. A dynamic programming algorithm can be used to determine how to arrange the keys in the tree so that the total cost of searching is minimized. Each node in the following binary search tree on the keys A through G is labeled .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.