Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 14.1, Problem 6E
Program Plan Intro
To show the insertion and the deletion operation of the sub-tree to maintain the rank of which it is the root.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Part (a): Show the result of inserting 2, 0, 5, 7, 9, 1, 6, 8, 3, 4 into an initially empty binary search tree.
Part (b): Show the result of deleting the root.
Note: in this question use the successor node (not the predecessor) for the replacement
Note this is a BST, not a Balanced BST.
Consider a traversal of a binary tree. Suppose that visiting a node means to
simply display the data in the node. What are the results of each of the following
traversals of the tree in the following figures according to:
a. Pre-order technique
b. Post-order technique
c. In-order technique
A
B
D
E
F
G
H
Find the kth smallest element. You can find the kth smallest element in a BST in O(n) time from an in-order iterator. For an AVL tree, you can find it in O(log n) time. To achieve this, add a new data field named size in AVLTreeNode to store the number of nodes in the subtree rooted at this node. Note the size of a node v is one more than the sum of the sizes of its two children. In the AVLTree class, add the following method to return the kth smallest element in the tree: public E find(int k) For the logic please refer to chapter 26 Programming Exercise 26.5.
Knowledge Booster
Similar questions
- 2. This question is about binary search tree.a. Show the final result after inserting 3, 1, 4, 6, 9, 2, 8, 5, 7, 0 into an empty binary search tree.b. Show the result of deleting the root twice. If the deleted node contains 2 children, its value is replaced by the minimum value of the right subtree, and the deletion is propagated. Show the result after each deletionarrow_forwardDraw a BST. Then write preorder, in-order and level order traversal. Also mention the height of the tree. Insert 15, 20, 25, 18, 16, 5, 30, 47 and 7. Insert 78, 45, 33, 89, 45, 20, 90, 100 and 8.arrow_forwardGiven a binary tree T and a source node s in it, provide the pseudocode for an iterative algorithm to traverse T starting from s using breadth-first traversal, also known as level-order traversal. Each node in T contains an integer key that can be accessed. Each time a node is visited, its key should be printed. Note: You do not have to implement your algorithm.arrow_forward
- Explain how an internal node of a Binary Search Tree (BST) is deleted. Take note that after the deletion, the result is still a BST.arrow_forwardDelete operation makes use of the FIND MIN operation discussed in the earliersection. The delete operation is carried out as follows:D1: If the node NODE to be deleted in the k-d tree is a leaf node, then deleteNODE.D2: If the node NODE to be deleted has DISC = i, and has a right subtree, thencall FIND MIN, to obtain the node RIGHT_MIN, which has the minimum elementalong dimension i in the right subtree and replace NODE with RIGHT_MIN.Recursively delete RIGHT_MIN from the right subtree.D3: If the node NODE to be deleted has DISC = i, and has a left subtree, thencall FIND MIN to obtain the node LEFT_MIN, which has the minimum elementalong dimension i in the left subtree and replace NODE with LEFT_MIN.Recursively delete LEFT_MIN from the left subtree. Move the revised left subtreeas the right child of the current node.illustrate a recursive pseudocode description of the delete operation in a k-d tree using above statementarrow_forwardAssume you have a binary search tree with 1000 nodes and you want to perform an in-order traversal of the tree. What is the time complexity of this operation?arrow_forward
- Modify the code on BST and implement the Delete Node algorithms. Consider all the three deleting algorithms. - a leaf node- a node with one child and- a node with two children Here is the code so far: #include <iostream>using namespace std; struct Tree{ char data; Tree *left; Tree *right; Tree *parent;};const int size=10; struct Tree *newTreeNode(int data) { Tree *node = new Tree; node->data = data; node->left = NULL; node->right = NULL; node->parent = NULL; return node;} struct Tree* insertTreeNode(struct Tree *node, int data){ static Tree *p; //retains its value between calls to this function Tree *retNode; if(node == NULL) { retNode = newTreeNode(data); retNode->parent = p; return retNode; } if(data <= node->data ) { p = node; node->left = insertTreeNode(node->left,data); } else { p = node; node->right = insertTreeNode(node->right,data); } return node;} Tree*…arrow_forwardExamine a traversal of a binary tree. Let's say that visiting a node means to display the data in the node. What are the result of each of the following traversals of the tree included? It is preorder, postorder, inorder or level order?arrow_forwardBased on an array implementation of a binary tree, construct an array version of a binary search tree using the simulated link approach. In addition to the array positions of the left and right children, each array element must maintain a reference to the data element that was initially placed there. In order to reuse such slots, you must additionally preserve a list of available array places with erased elements.arrow_forward
- Suppose you are given an undirected graph G and a start node s. Your task is to design an algorithm that returns FALSE if G is not a tree and returns TRUE and labels each vertex v with the number of nodes in the subtree rooted at v if G is a tree. Note that the orientation of edges is implicit given the start node. Hint: Modify DFS to solve the problem.arrow_forwardThe mapping approach that converts a whole binary tree to a vector can be used to store general trees, but in an inefficient manner. The method is to reserve enough space to keep the lowest, rightmost leaf and to keep null references in nodes that are not currently in use. What is the smallest possible Vector length required to store an n-element binary tree?arrow_forwardDraw the BST constructed by inserting the values [53, 25, 11, 63, 4, 88,59, 3, 15, 82, 92, 27, 55, 14] in the order shown, into an initially emptytree.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education