{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

chap14-solutions - Selected Solutions for Chapter 14...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Selected Solutions for Chapter 14: Augmenting Data Structures Solution to Exercise 14.1-7 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: # of inversions D n X j D 1 j In ±.j / j ; where In ±.j / D f i W i < j and AŒi > AŒj g . Note that j In ±.j / j is related to AŒj ’s rank in the subarray AŒ1 : : j because the elements in In ±.j / are the reason that AŒj is not positioned according to its rank. Let r.j / be the rank of AŒj in AŒ1 : : j . Then j D r.j / C j In ±.j / j , so we can compute j In ±.j / j D j NUL r.j / by inserting AŒ1 ; : : : ; AŒn into an order-statistic tree and using OS-R ANK to find the rank of each AŒj in the tree immediately after it is inserted into the tree. (This OS-R ANK value is r.j / .) Insertion and OS-R ANK each take O. lg n/ time, and so the total time for n ele- ments is O.n lg n/ . Solution to Exercise 14.2-2 Yes, we can maintain black-heights as attributes in the nodes of a red-black tree without affecting the asymptotic performance of the red-black tree operations. We appeal to Theorem 14.1, because the black-height of a node can be computed from the information at the node and its two children. Actually, the black-height can be computed from just one child’s information: the black-height of a node is the black-height of a red child, or the black height of a black child plus one. The second child does not need to be checked because of property 5 of red-black trees. Within the RB-I NSERT -F IXUP and RB-D ELETE -F IXUP procedures are color changes, each of which potentially cause O. lg n/ black-height changes. Let us
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
14-2
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern