tailieunhanh - Introduction to Algorithms Second Edition Instructor’s Manual 2nd phần 6

Nếu có sự chồng chéo trong trái cây con, được thực hiện. Nếu không có chồng chéo lên nhau ở bên trái, cho thấy không có chồng chéo lên nhau ở bên x phần tử trong một nút T cây để n-Thống kê và một số tự nhiên tôi, các thủ tục sau đây lấy sự kế thừa thứ i x theo thứ tự tuyến tính của | 14-8 Lecture Notes for Chapter 14 Augmenting Data Structures If search goes left If there is an overlap in left subtree done. If there is no overlap in left show there is no overlap in right. Went left because low i max left x high j for some j in left subtree . Since there is no overlap in left i and j don t overlap. Refer back to no overlap if low i high j or low j high i . Since low i high j must have low j high i . Now consider any interval k in right subtree. Because keys are low endpoint low j low k . in left in right Therefore high i low j low k . Therefore high i low k . Therefore i and k do not overlap. theorem Solutions for Chapter 14 Augmenting Data Structures Solution to Exercise Given an element x in an n-node order-statistic tree T and a natural number i the following procedure retrieves the ith successor of x in the linear order of T OS-Successor T x i r OS-Rank T x s r i return OS-Select root T s Since OS-Rank and OS-Select each take O lgn time so does the procedure OS-Successor. Solution to Exercise When inserting node z we search down the tree for the proper place for z. For each node x on this path add 1 to rank x if y is inserted within x s left subtree and leave rank x unchanged if y is inserted within x s right subtree. Similarly when deleting subtract 1 from rank x whenever the spliced-out node y had been in x s left subtree. We also need to handle the rotations that occur during the hxup procedures for insertion and deletion. Consider a left rotation on node x where the pre-rotation right child of x is y so that x becomes y s left child after the left rotation . We leave rank x unchanged and letting r rank y before the rotation we set rank y r rank x . Right rotations are handled in an analogous manner. Solution to Exercise Let A 1. n be the array of n distinct numbers. One way to count the inversions is to add up for each element the number of larger elements that precede it in the array 14-10 Solutions for Chapter 14 .