Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the pseudocode of the singleRotation method, corresponding to the proper single-rotation restructure operation in an AVL-tree, and started for you in the partial pseudocode

Complete the pseudocode of the singleRotation method, corresponding to the proper single-rotation restructure operation in an AVL-tree, and started for you in the partial pseudocode given in Algorithm 5, by matching the five missing statements (in line indexes 2, 4, 6, 8, and 11), listed on the left-hand side below, with the corresponding operation, listed on the right-hand side below. (For your convenience, the pseudocode for the auxiliary method makeChild is given in Algorithm 6. Assume that the auxiliary method resetHeight, which takes as input a node w in the AVL tree and resets its height with respect to the subtree rooted at w, if needed, has been properly implemented.)image text in transcribed

5. (10 pts.] Complete the pseudocode of the SINGLEROTATION method, corresponding to the proper single-rotation restructure operation in an AVL-tree, and started for you in the par- tial pseudocode given in Algorithm 5, by matching the five missing statements in line in- dexes 2, 4, 6, 8, and 11), listed on the left-hand side below, with the corresponding oper- ation, listed on the right-hand side below. (For your convenience, the pseudocode for the auxiliary method MAKECHILD is given in Algorithm 6. Assume that the auxiliary method RESET HEIGHT, which takes as input a node w in the AVL tree and resets its height with respect to the subtree rooted at w, if needed, has been properly implemented.) Algorithm 5 SINGLE ROTATION(y, 2) 1: rotate Left? + y = z.right 3: if rotate Left? then 5: else Algorithm 6 MAKECHILD(p, c, left?) 1: if left? then 2: p.left + c 3: else 4: p.right + c 5: if c# NULL then 6: c.parent p 7: MAKECHILD(y, z, rotate Left?) 9: MAKECHILD(w, y, w.left = 2) 10: RESETHEIGHT(2) 11: 12: RESETHEIGHT(w) 13: return y Statement # Operation Statement 2 MAKECHILD(z,Ty, not rotate Left?) Statement 4 Ty + y.left Statement 6 reset Height(y) Statement 8 w + z.parent Statement 11 Tyy.right 5. (10 pts.] Complete the pseudocode of the SINGLEROTATION method, corresponding to the proper single-rotation restructure operation in an AVL-tree, and started for you in the par- tial pseudocode given in Algorithm 5, by matching the five missing statements in line in- dexes 2, 4, 6, 8, and 11), listed on the left-hand side below, with the corresponding oper- ation, listed on the right-hand side below. (For your convenience, the pseudocode for the auxiliary method MAKECHILD is given in Algorithm 6. Assume that the auxiliary method RESET HEIGHT, which takes as input a node w in the AVL tree and resets its height with respect to the subtree rooted at w, if needed, has been properly implemented.) Algorithm 5 SINGLE ROTATION(y, 2) 1: rotate Left? + y = z.right 3: if rotate Left? then 5: else Algorithm 6 MAKECHILD(p, c, left?) 1: if left? then 2: p.left + c 3: else 4: p.right + c 5: if c# NULL then 6: c.parent p 7: MAKECHILD(y, z, rotate Left?) 9: MAKECHILD(w, y, w.left = 2) 10: RESETHEIGHT(2) 11: 12: RESETHEIGHT(w) 13: return y Statement # Operation Statement 2 MAKECHILD(z,Ty, not rotate Left?) Statement 4 Ty + y.left Statement 6 reset Height(y) Statement 8 w + z.parent Statement 11 Tyy.right

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions