Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSE3358 Problem Set 8: AVL Trees and Dishonest Successor in Red-Black Trees, Exams of Data Structures and Algorithms

Problem set 8 from a computer science engineering course, focusing on avl trees and the implementation of a dishonest successor operation in red-black trees. Students are required to show the results of inserting keys into red-black trees and avl trees, prove properties about avl trees, and implement the dishonest successor operation in a red-black tree. The document also includes a problem about finding minimum and successor keys in a b-tree and determining if two rectangles overlap.

Typology: Exams

2012/2013

Uploaded on 04/07/2013

seshu_lin3
seshu_lin3 🇮🇳

4

(3)

59 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE3358 Problem Set 8
03/18/05
Due 03/25/05
Problem 1: Practice Insertions (10 points)
Show the results of insering the following keys
F, S, Q, K, C, L, H, T, V, W, R, N, P, A, B, X, Y, D, Z, E
in the order shown into an originally empty
(a) (5 points) Red-Black Tree
(b) (5 points) B-tree with t= 2
Problem 2: AVL tree (30 points)
In 1962, Adelson-Velskii and Landis invented the AVL tree. An AVL tree is a binary search tree that
satisfies the following additional property:
AVL property: For any node x,|h[lef t[x]] h[right[x]]| 1 where h[x] denotes the height of x, and
we define h[NI L] = 1.
In other words, the heights of the left and right subtrees (children) of a node differ by at most one.
(a) (5 points) Let S(h) be the minimum number of nodes in an AVL tree of height h. Show that
S(0) = 1 and S(1) = 2 and that for h2, S(h) = S(h1) + S(h2) + 1.
(b) (5 points) Using induction, show that S(h)φh, where φ=1+5
2.
(c) (5 points) Conclude that the height hof an AVL tree on nnodes satisfies h= Θ(log n).
(d) (15 points) Given that every node xstores its height h[x], an AVL tree can be maintained after an
insertion operation. Here’s how: After inserting a new node xas a leaf, we set h[x] = 0 and we go up
the tree updating the height of every node on the path from xto the root by incrementing its height
by 1. When we encounter the first node yfor which |h[left[y]] h[right[y]]|= 2 (if any), we fix the
AVL property for yby performing rotations. Depending on the position of xrelative to y, different
rotation(s) must be performed. We have two cases to consider (the other cases are symmetric)
case 1: xis in the left subtree of lef t[y]
case 2: xis in the right subtree of lef t[y]
The above two cases suggest that, since node yviolates the AVL property after insertion, the left
subtree of yis higher than the right subtree of y(the insertion was done in the left subtree of y),
and the height difference is 2 (more than 1). For each of the two above cases, describe the rotation(s)
required to re-establish the AVL property for node y. Argue that after re-establishing the AVL property
for node y, no more height updates or fixes will be needed, i.e. the resulting tree is AVL.
1
pf2

Partial preview of the text

Download CSE3358 Problem Set 8: AVL Trees and Dishonest Successor in Red-Black Trees and more Exams Data Structures and Algorithms in PDF only on Docsity!

CSE3358 Problem Set 8 03/18/ Due 03/25/

Problem 1: Practice Insertions (10 points) Show the results of insering the following keys F, S, Q, K, C, L, H, T, V, W, R, N, P, A, B, X, Y, D, Z, E in the order shown into an originally empty (a) (5 points) Red-Black Tree (b) (5 points) B-tree with t = 2 Problem 2: AVL tree (30 points) In 1962, Adelson-Velskii and Landis invented the AVL tree. An AVL tree is a binary search tree that satisfies the following additional property: AVL property: For any node x, |h[lef t[x]] − h[right[x]]| ≤ 1 where h[x] denotes the height of x, and we define h[N IL] = −1. In other words, the heights of the left and right subtrees (children) of a node differ by at most one. (a) (5 points) Let S(h) be the minimum number of nodes in an AVL tree of height h. Show that S(0) = 1 and S(1) = 2 and that for h ≥ 2, S(h) = S(h − 1) + S(h − 2) + 1.

(b) (5 points) Using induction, show that S(h) ≥ φh, where φ = 1+ 2 √ 5. (c) (5 points) Conclude that the height h of an AVL tree on n nodes satisfies h = Θ(log n). (d) (15 points) Given that every node x stores its height h[x], an AVL tree can be maintained after an insertion operation. Here’s how: After inserting a new node x as a leaf, we set h[x] = 0 and we go up the tree updating the height of every node on the path from x to the root by incrementing its height by 1. When we encounter the first node y for which |h[lef t[y]] − h[right[y]]| = 2 (if any), we fix the AVL property for y by performing rotations. Depending on the position of x relative to y, different rotation(s) must be performed. We have two cases to consider (the other cases are symmetric)

  • case 1: x is in the left subtree of lef t[y]
  • case 2: x is in the right subtree of lef t[y]

The above two cases suggest that, since node y violates the AVL property after insertion, the left subtree of y is higher than the right subtree of y (the insertion was done in the left subtree of y), and the height difference is 2 (more than 1). For each of the two above cases, describe the rotation(s) required to re-establish the AVL property for node y. Argue that after re-establishing the AVL property for node y, no more height updates or fixes will be needed, i.e. the resulting tree is AVL.

Problem 3: The dishonest successor (30 points) As you know, the homework policy states that dishonest students are given red tags. Therefore, every student has a grade and a red-tag boolean flag to identifying whether the student is dishonest or not. We wish to support all dynamic set operations on students such as INSERT, DELETE, SEARCH, MINIMUM, MAXIMUM, SUCCESSOR, PREDECESSOR in addition to the following operation: Given a student x with grade k, find the dishonest student y (if any) with the lowest grade k′^ such that k′^ > k in O(log n) time, where n is the number of students. In other words, given a student x, we wish to find the dishonest successor of x in O(log n) time. Explain how you can augment a red-black tree to support this operation. In doing so, describe the 4 steps discussed in class: (a) (0 points) Choose the underlying data structure (red-black tree in this case) and determine what constitute the keys. (b) (10 points) Identify the additional information that will augment the red-black tree (c) (10 points) Argue that the additional information can be maintained easily by insertion and deletion and describe how it is maintained by rotations (d) (10 points) Provide a pseudocode for the operation DISHONEST-SUCCESSOR(x) Problem 4: Some B-tree operations (30 points) Given a B-tree T with minimum degree t, describe an algorithm that: (a) (10 points) Finds (x, i) in O(logt n) time such that keyi[x] is the MINIMUM key in T. (b) (10 points) Given (x, i), finds (y, j) such that keyj [y] is the SUCCESSOR of keyi[x] in T in time: O(logt n) if x is a non-leaf O(log 2 n) if x is a leaf (c) (10 points) Given k, finds (x, i) in O(log 2 n) time such that keyi[x] = k in T. Problem 5: Overlaping rectangles (20 points) VLSI databases commonly represent an integrated circuit as a list of rectangles. Assume that each rectangle is rectilinearly oriented (sides parallel to the x- and y-axis), so that a representation of a rectangle consists of its minimum and maximum x- and y-coordinates. Give an O(n log n) time algorithm to decide whether or not a set of rectangles so represented contains two rectangles that overlap. Your algorithm need not report all intersecting pairs, but it must report that an overlap exists if one rectangle entirely covers another, even if the boundary lines do not intersect. (Hint: Move a “sweep” line across the set of rectangles and maintain their heights in an interval tree).