Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8. Write a C++ function item, TreeNode T) that inserts item into the binary sear

ID: 3896523 • Letter: 8

Question

8. Write a C++ function item, TreeNode T) that inserts item into the binary search tree r. After the insertion, T must remain a binary search tree. You may assume that txse item tvse values are comparable using the --, C operators. Draw the binary search tree resulting from sequentially calling bstnse on an initially empty binary tree with the values 9,12,5,15,7,10,18 If T- null Empty tree Root- new TreeNode(item) Return If (T -> tree item type equals item) Else if (T ? tree item type is greater than item) Else if (T ? tree-ten-type is less than item) Return Call bst insert of item on T pointing to left Call bst insert of item on T pointing to right 12 10 15 18

Explanation / Answer

The tree that you have drawn is correct as the bst property is maintained as we can see that all the values greater than 9 are to the right of tree whereas all the values smaller than 9 are to the left of tree.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote