Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
Question
Book Icon
Chapter 12, Problem 1P

(a)

Program Plan Intro

To describes the asymptotic performance of TREE-INSERT for identical n -keys insertion into empty BST.

(a)

Expert Solution
Check Mark

Explanation of Solution

The insertion in BST first find the suitable place for the node so that after adding the node the properties of the BST remains holds so it need to compare all the nodes with the key and find the successor of the key.

The TREE-INSERT algorithm chooses the suitable place for the node and inserts the key to the right of the rightmost sub-tree and rotates the tree so that the balancing of the tree remains the same.

The comparison of the key with each node of the tree takes the time of Θ(n2) for n nodes of tree.

Thus, the algorithm TREE-INSERT takes total cost of Θ(n2) .

(b)

Program Plan Intro

To explains the role of Boolean flag variable during insertion of key in BST.

(b)

Expert Solution
Check Mark

Explanation of Solution

The flag is the temporary variable used to indicate the status of the insert operation. If the insertion operation is already insert another key in the tree then the value of flag variable will be false that means another insert operation is on the way and after the completion of the operation its values is updates to true.

The true value if the variable represent that it can perform the insertion operation without any issues.

When the insert operation starts it set the values of the flag variable to flag so that other process can identify that some operation is still running.

Thus, the Boolean variable has very important role in the insertion of key in the BST as to hold the status of the operation.

(c)

Program Plan Intro

To explaintime taken by the list of equal keys at x and insert z into the list.

(c)

Expert Solution
Check Mark

Explanation of Solution

For the insertion of key into the equal to x that means the position is already marked and there is no need of comparisons then the algorithm performs the operations in the linear time.

In this case the insertion is depends upon the height of the tree and the number of node it have.

Thus, the operation is performed in constant linear time.

(d)

Program Plan Intro

To finds the worse-case performanceand expected running time for setting x to either x.left or x.right .

(d)

Expert Solution
Check Mark

Explanation of Solution

The setting operation required some comparisons so that it found the suitable position for the key as right or left sub-tree of the BST so it uses the comparison algorithm that compare the key with all tree nodes.

The comparison takes total time of Θ(n2) to compare the key with all the elements as the tree has total n nodes.

In worse-case it randomly choose the node as it right of left sub-tree of the same BST and the number of comparisons required to find the suitable position is maximum is Θ(n2) .

The expected running tome of the algorithm is the equals to the depth of the tree that is lgn and the number of nodes in the tree so the expected time of the algorithm is O(nlgn) .

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
In the worst-case situation, binary tree sort using a self-balancing binary search tree requires O(n log n) time, which is slower than merge sort.
In which order would you need to insert the values 68, 99, 24, 47, 30, 74, 97 into an initially empty binary search tree in order to get a full binary search tree? A 'full binary search tree' is a tree in which every node other than the leaves has two children. Draw the resulting tree. IMPORTANT: The penalty scheme for this question is 0, 50, 100%. Answer: (penalty regime: 0, 50, 100 %) Help Clear Check
How many references must you change to insert a node to a binary search tree? What is the average time complexity for search, insert and delete operations in a balanced Binary Search Tree of size n? What is the worst case time complexity for search, insert and delete operations in a Binary Search Tree of size n? Suppose some numbers (given) are inserted in that order into an initially empty binary search tree. What is the In-order/Pre-order/Post-order traversal sequence of the resultant tree?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education