This preview has intentionally blurred sections. Sign up to view the full version.
View Full 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.21 on page 310 Let T be an augmented orderstatistic 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.22 on page 310 Yes, by Theorem 14.1, because the blackheight of a node can be computed from the information at the node and its two children. Actually, the blackheight can be computed from just one child.s information: the blackheight of a node is the blackheight 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 redblack trees. Within the RBINSERTFIXUP and RBDELETEFIXUP procedures are color changes, each of which potentially cause O (lg n ) blackheight changes. Let us show that the color changes of the fixup procedures cause only local blackheight changes and thus are constanttime operations. Assume that the blackheight of each node x is kept in the field bh [ x ]. For RBINSERTFIXUP, there are 3 cases to examine. (a) z’s uncle is red.Before color changes, suppose that all subtrees α , β , γ , δ , ² have the same blackheight 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 blackheight changed is node C. To Tx that, add bh [ p [ p [ z ]]] = bh [ p [ p [ z ]]] + 1 after line 7 in RBINSERTFIXUP. . 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.
 Spring '08
 KAPOOR
 Algorithms

Click to edit the document details