hw4-solns - Illinois Institute of Technology Department of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Illinois Institute of Technology Department of Computer Science Homework Assignment 4 Solutions CS 430 Introduction to Algorithms Spring Semester, 2009 1. Problem 14.2-1 on page 310 Let T be an augmented order-statistic tree. We can add pointers for each node to point to its successor and predecessor if exists. Previously, we have one pointer to point to a root of T, and each node contains value and pointers to left child and right child. Now, we have additional pointers to point to maximum and minimum, and each node contains pointers to their successors and predecessors. When a new node, termed as x, inserts, we can split into two cases, inserting into left child or right child. When x inserts into a left child, p [ x ]- > predecessor- > successor = x x- > successor = p [ x ] x- > predecessor = p [ x ]- > predecessor p [ x ]- > predecessor = x When x inserts into a right child, we can do the same way as previous.(symmetrically) For pointers with maximum and minimum, when new node comes in, we can compare in constant time. 2. Problem 14.2-2 on page 310 Yes, by 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-INSERT-FIXUP and RB-DELETE-FIXUP procedures are color changes, each of which potentially cause O (lg n ) black-height changes. Let us show that the color changes of the fixup procedures cause only local black-height changes and thus are constant-time operations. Assume that the black-height of each node x is kept in the field bh [ x ]. For RB-INSERT-FIXUP, there are 3 cases to examine. (a) z’s uncle is red.Before color changes, suppose that all subtrees α , β , γ , δ , ² have the same black-height k with a black root, so that nodes A, B, C, and D have blackheights of k + 1. . After color changes, the only node whose black-height changed is node C. To Tx that, add bh [ p [ p [ z ]]] = bh [ p [ p [ z ]]] + 1 after line 7 in RB-INSERTFIXUP. . Since the number of black nodes between p[p[z]] and z remains the same, nodes above p [ p [ z ]] are not affected by the color change....
View Full Document

This note was uploaded on 04/07/2009 for the course CS 430 taught by Professor Kapoor during the Spring '08 term at Illinois Tech.

Page1 / 4

hw4-solns - Illinois Institute of Technology Department of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online