Consider a binary search tree where each node v has a field v.height that store Doted at v. Note: The height is not the same as the size field we discussed in class. In umber of edges in the longest path from v to a leaf of the subtree rooted at (a) Modify the Tree Insert procedure (discussed in class and described in t the height fields so that all the height fields of the troo or porrooted ofte:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please show steps clearly

 

4. Consider a binary search tree where each node v has a field v.height that stores the height of the subtree
rooted at v.
(Note: The height is not the same as the size field we discussed in class. In particular, v.height is the
number of edges in the longest path from v to a leaf of the subtree rooted at v.)
(a) Modify the TreeInsert procedure (discussed in class and described in the course notes) to update
the height fields so that all the .height fields of the tree are corrected after applying the Tree Insert
operation. (Assume that all the .height fields were correct before the TreeInsert operation.) Your
modified algorithm should take the same asymptotic running time as the original TreeInsert
operation. Explain your modification and give pseudo-code for the modified algorithm.
(b) Analyze the running time of your modified procedure in terms of the height of the binary search
tree.
Transcribed Image Text:4. Consider a binary search tree where each node v has a field v.height that stores the height of the subtree rooted at v. (Note: The height is not the same as the size field we discussed in class. In particular, v.height is the number of edges in the longest path from v to a leaf of the subtree rooted at v.) (a) Modify the TreeInsert procedure (discussed in class and described in the course notes) to update the height fields so that all the .height fields of the tree are corrected after applying the Tree Insert operation. (Assume that all the .height fields were correct before the TreeInsert operation.) Your modified algorithm should take the same asymptotic running time as the original TreeInsert operation. Explain your modification and give pseudo-code for the modified algorithm. (b) Analyze the running time of your modified procedure in terms of the height of the binary search tree.
If your solution involves incrementing the height of all nodes on the path to the root when the inserted node does not have a sibling, then, you should explicitly
state that you will be assuming that the inserted node is at the lowest level of the tree, namely, the inserted node is on the longest path from the root to a leaf.
Note that if you do not make this assumption and the inserted node does not have a sibling, then the height of some nodes on the path to the root may not need
to be incremented and an additional check is required at each node on the path to the root.
If you want to provide the most general solution without making the assumption above, then you need to carefully think about what needs to be checked at each
node on the path to the root when the inserted node does not have a sibling. In particular, when the inserted node does not have a sibling, then rather than directly
incrementing the height of every node on the path to the root, there should be another formula to update the height of each node on that path.
Transcribed Image Text:If your solution involves incrementing the height of all nodes on the path to the root when the inserted node does not have a sibling, then, you should explicitly state that you will be assuming that the inserted node is at the lowest level of the tree, namely, the inserted node is on the longest path from the root to a leaf. Note that if you do not make this assumption and the inserted node does not have a sibling, then the height of some nodes on the path to the root may not need to be incremented and an additional check is required at each node on the path to the root. If you want to provide the most general solution without making the assumption above, then you need to carefully think about what needs to be checked at each node on the path to the root when the inserted node does not have a sibling. In particular, when the inserted node does not have a sibling, then rather than directly incrementing the height of every node on the path to the root, there should be another formula to update the height of each node on that path.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education