(a)
To describes the asymptotic performance of TREE-INSERT for identical n -keys insertion into empty BST.
(a)
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
The comparison of the key with each node of the tree takes the time of
Thus, the algorithm TREE-INSERT takes total cost of
(b)
To explains the role of Boolean flag variable during insertion of key in BST.
(b)
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)
To explaintime taken by the list of equal keys at x and insert z into the list.
(c)
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)
To finds the worse-case performanceand expected running time for setting x to either x.left or x.right .
(d)
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
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
The expected running tome of the algorithm is the equals to the depth of the tree that is
Want to see more full solutions like this?
Chapter 12 Solutions
Introduction to Algorithms
- In the worst-case scenario, binary tree sort employing a self-balancing binary search tree requires O(n log n) time, which is slower than merge sort.arrow_forwardIn the worst case, binary tree sort utilising a self-balancing binary search tree requires O(n log n) time, but it is still slower than merge sort.arrow_forwardProblem 2 : Consider the following binary search tree: 42 24 57 12 30 44 63 29 36 49 31 Show the resulting tree if you delete the entry with key = 42 from the above tree. You need to describe, step by step, how the resulting tree is generated.arrow_forward
- E. D 2. In the binary search tree above, finding node E requires one comparison and finding node A requires four comparisons. What is the expected number of comparisons required to find a node chosen at random?arrow_forwardDraw a binary search tree and AVL tree from the following traversals: {15, 5, 20, 70, 3, 10, 60, 90, 16} Convert Binary Search Tree into Binary Tree such that sum of all greater keys is added to every key.arrow_forwardIn the worst-case scenario, binary tree sort employing a self-balancing binary search tree requires O(n log n) time.arrow_forward
- The post order traversal for the given Binary Search Tree is: Root Node 30 15 60 7 22 45 75 Click Save and Submit to save and submit. Click Save All Answers to save all answers. Save All An 74 S Fe *- F11 ** F7 F10 F12 %23 6 T. Y U P 41 G H. X, C V しの * 00 FLarrow_forward3. The following is a recursive algorithm for a preorder binary tree traversal. Determine the worst-case runtime of this algorithm where the proper binary tree t has n internal nodes (non null nodes). Do this by specify the recurrence equation for the runtime T(n) and then deriving the closed form. Count the comparison v != null as 1 primary operation and the call processNode(t,v) as c primary operations, where c is some constant. Algorithm preorder(Tree t, TreeNode v) Input: Binary tree t of size n and node v of t Output: None if v!= null then end end processNode(t.v) preorder(t,v.getLeft()) preorder(t,v.getRight())arrow_forwardIn which order would one have to insert the keys 1 to n for an n ∈ N in a binary search tree,in order to minimize the number of comparisons during construction?arrow_forward
- Assuming that there are no duplicate keys in a binary search tree, develop an algorithm to determine the post-order traversal of the tree based on its pre-order traversal. For example, given the pre-order traversal: 5 214 3 12 10 9 15. The output is 1 3 4 2 9 10 15 12 5.arrow_forwardUsing Java code Do the given, Using the Necessary conditions, Recover the Binary Search tree (T) from the given Post order Traversal. Example: Input: 5, 18, 15, 25, 20, 35, 45, 60, 50, 40, 30 Output: 30, 20, 40, 15, 25, 35, 50, 5, 18, 45, 60arrow_forwardUsing Java Design an algorithm for the following operations for a binary tree BT, and show the worst-case running times for each implementation:preorderNext(x): return the node visited after node x in a pre-order traversal of BT.postorderNext(x): return the node visited after node x in a post-order traversal of BT.inorderNext(x): return the node visited after node x in an in-order traversal of BT.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education