(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 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
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
- Consider a binary search tree (BST) whose elements are the integer values: Starting with an empty BST, show the effect of successively adding the following elements: 15, 78, 10, 5, 12, 82, 60, 68, 11 and 65. Show the effect of successively deleting 10, 78, and 15 from the resulting BST. Traverse the original BST in pre-order and post-order.arrow_forwardSuppose T is a binary tree with 17 nodes. What is the minimum possible depth of T? 1 3 4 2 A binary tree of N nodes has _______. Log2 N levels N / 2 levels Log10 N levels N x 2 levels The difference between a binary tree and a binary search tree is that : in binary search tree nodes are inserted based on the values they contain none of these in binary tree nodes are inserted based on the values they contain a binary search tree has two children per node whereas a binary tree can have none, one, or two children per node What is the best code for the following procedure: AddStudent(studentName):add a new student to an array of alphabetically ordered names . Hint: We must shift some students. size contains the number of students in the array AddStudent(studentName){ int i ; for( i=0; i< size-1; i++){ if(arr[i].compareTo( studentName)>0) break; for(int j= size-1 ; j >i…arrow_forwardLet T be a binary search tree whose keys are all distinct. Suppose T is created by inserting each key into the growing tree. Let x be a leaf node and y be its parent node. Show that if x is the right child of y, then y.key is the largest key in T smaller than x.key. (Hint: Show that the assumption that there is another node z whose key satisfies y.key < z.key < x.key will lead to a contradiction.)arrow_forward
- This exercise is about drawing BSTs. You are asked to: Show the result of inserting 3, 1, 4, 6, 9, 2, 5, and 7 in an initially empty binary search tree. Then show the result of deleting the root. Draw all binary search trees that can result from inserting permutations of 1, 2 and 3. How many types of trees are there? What are the probabilities of each type of tree’s occurring if all permutations are equally likely Given the input {4371, 1323, 6173, 4199, 4344, 9679, 1989}, a fixed table size of 10, and a hash function H(X) = X mod 10, show the resulting Linear probing hash table Separate chaining hash tablearrow_forwardDraw the binary search tree that would result if the given elements were added to an empty binary search tree in the given order. Use paint to draw. a. Lisa, Bart, marge, maggie, flanders, smithers, miljouse b. 12,34,1,5,-5,6,19,45,2,-7,47arrow_forward2. Show the B+‐tree of order three (namely each node has a maximum of three keys/descendents) that result from loading the following sets of keys in order: a. M, I, T b. M, I, T, Q, L, H, R, E, K c. M, I, T, Q, L, H, R, E, K, P d. M, I, T, Q, L, H, R, E, K, P, C, Aarrow_forward
- The time complexity of traversing a binary search tree that contains 'n' elements is O (n) in the worst case.The time complexity of traversing a red-black tree that contains 'n' elements is O (log2 n) in the worst case.Traversing a binary search tree, which contains integers, according to the "inorder" principle always gives us integers in sorted ascending order.If we insert a sequence of integers in an empty BST, it will always be at least as high as the tree we get if we insert the same sequence of integers in an empty red-black tree.If we insert a sequence of integers in an empty BST, it will always be twice as high as the tree we get if we insert the same sequence of integers in an empty red-black tree.Group of answer options Only statements A, B, C and D are correct. Only statements A, B and C are correct. All statements are correct. Only statements A, C, D and E are correct. Only statements A, C and D are correct.arrow_forwardPerform what is asked. Show your solutions.1. Given the expression A - B / C * (D + E), convert to PREFIX and POSTFIX.2. Given the expression (A / B) ^ C * D, convert to PREFIX and POSTFIX. 3. Given the expression A || B && !C || !D, convert to PREFIX and POSTFIX. 4. Create a binary search tree using the following insertions.44, 88, 55, 77, 33, 99, 66, 22, 25, 75Based on the final tree, what is the preorder traversal of the tree?5. Create a binary search tree using the following insertions.44, 88, 55, 77, 33, 99, 66, 22, 25, 75Based on the final tree, what is the postorder traversal of the tree?arrow_forwardCreate a binary search tree as discussed in class, using the given numbers in the order they’re presented. State if the resulting tree is has the attributes of being FULL, BALANCED, or COMPLETE. 37, 20, 18, 56, 40, 42, 12, 5, 6, 77, 21, 54arrow_forward
- Consider an input: 5, 3, 10, 7, 8, 4, 1, 13, 11, 2, 15, 16 Create a Binary Search Tree (Read the input from left to right) Write in-order traversal of the tree Delete node 10 and redraw the tree B2. a. Find a closed form for the generating function for the given sequence 4, 16, 64, 256, … B2. b. Find the coefficient of x^9 in the power series of this function f(x)=1/(1-2x)^2 B2. c. What is the probability that a bit string of length 8 has exactly four 1’s?arrow_forwardSuppose that instead of each node x keeping the attribute x.p, pointing to x’s parent, it keeps x.succ, pointing to x’s successor. Give pseudocode for SEARCH, INSERT, DELETE, and EDIT routine on a binary search tree T using this representation. These procedures should operate in time O(h), where h is the height of the tree T. (Hint: You may wish to implement a subroutine that returns the parent of a node.) Show these types of pseudocode using java. Data structures and algorithmsarrow_forwardLet T1, T2 be 2-3-4 trees and let x be a key [in neither T1, T2], such that for each pair of keys x1 ∈ T1 and x2 ∈ T2, we have x1 < x < x2. Thus, every key in T1 is smaller than every key in T2. Devise an algorithm that constructs the union of x with these two trees. Of course, the trees T1, T2 may be of different height, and the result must be a valid 2-3-4 tree. Your algorithm should run in O(1 + |h(T1) − h(T2)|).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