Present an algorithm to delete a tree. In other words, implement the following function: void deleteTree(TreeNode *root)
Added by Alexander B.
Close
Step 1
First, we need to check if the root is null. If it is, then the tree is already empty, so we can simply return. Show more…
Show all steps
Your feedback will help us improve your experience
Vysakh M and 66 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
A binary tree is a type of tree data structure in which each node has at most two children, referred to as the left child and the right child. The topmost node of the tree is called the root. Each node in the tree, except for the root, has a parent node. The nodes that have no children are called leaf nodes. A sub-tree is a tree that is formed by selecting a node and all its descendants. The height of a binary tree is the maximum number of edges in the longest path from the root to a leaf node. The depth of a node is the number of edges from the root to that node.
Madhur L.
1) (ABET: 6) Draw the Binary Search Tree that would result if the following numbers were inserted into the tree in the following order: 30, 12, 10, 40, 50, 45, 60, 17. 2) (ABET: 6) Using the delete routine we discussed in class show what the above tree would look like if the root node were deleted. 3) (ABET: 6) Again, using the delete routine we discussed in class show what the tree in the previous problem would look like if its root node were deleted.
if a node having two children is to be deleted from a binary search tree, it is replaced by its
Haricharan G.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD