CLRS 15.5 Best binary search tree

Source: Internet
Author: User

15.5-1
Construct-optimal-bst (Root)
N←length[root]
Print r[1, n] is the root
PRINT-OBST (1, N)

Print-obst (i, J)
m = R[i, j]
If i = m
Print dm−1 D_{m-1} is the only child of the K_m
Else
Print kr[i,m−1] k_{r[i, M-1]} is the left child of K_m
Print-obst (i, m-1)
If j = m
Print DM d_m is the right child of the K_m
Else
Print Kr[m+1,j] k_{r[m+1, J]} is the right child of K_m
Print-obst (M+1, J)

15.5-2
The right binary search tree is shown below:

The cost of the final calculation is: 3.12.

15.5-3
If you have a Ω\omega table, each calculation of ω[i,j] \omega[i,j] requires only θ (1) \theta (1) time, and no maintenance table requires θ (j−i) \theta (j-i) time, so it is now equivalent to adding a for loop in the second for (not is nested in a third for loop), and the final complexity remains Θ (n3) \theta (n^3).

15.5-4
The 9th and 10 lines are replaced by:
If i = j
R = J
e[i,j]= PI+QI−1+QJ P_i+q_{i-1}+q_j
Else
for r = root[i,j-1] to Root[i+1,j]

When calculating all j−i=k j-i=k E[i,j] (with K-K nodes), each e[i,j] will cost root[i+1, J]–root[i, j-1] + 1 iterations, all j−i=k j-i=k] spend e[i,j] –ROOT[1,K] + n–k. Due to 1≤root[k, 1], root[1, k]≤n, so root[k,1]–root[1,k] + n–k=θ (n). The last K K change range is 0 0 to N

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.