11. Assume the tree on Figure 2 is a BST and we want to insert number "g" in it. What is the output of Int Tree.insert(8
Posted: Sat May 14, 2022 6:42 pm
11. Assume the tree on Figure 2 is a BST and we want to insert number "g" in it. What is the output of Int Tree.insert(8)2 Trace the code below. You can draft a tree in the empty square below and visually explain using this tree how the insertion worked step by step. Output: (3 points) goverride ** suert element into the binary tree Return true tf the lett tarted accessfully public hoolean insert() { 1 root - null) reet - createdodele); // Create a new root se Locate the parent node Treelodec parent - null; Treetode turret - roti while (current I null) IF (c.compare(e, current element).) parent - current current current.lft > else if (c.comparece, current element) > 0) parent -currenti current current.righti return false; // Duplicate node not Inverted // Create the new node and attach it to the parent mode if (s.compare(e, parent.element) parent.left - cresteetide() else parent.right - createnetlode(e)s 3 sre return true; / Element inserted successfully >
CPS2232 Final Exam Spring 2022 12. Assume the tree on Figure 2modified in step 11 (if appropriate), is a BST and we want to insert number -38" in it. What is the output of our free.insert(34/7 Trace the code above. You can Sketch a tree in the emply square below and visually explain using this tree how the insertion was performed step by step Output: (3 points) powiat By te tre mesta (E) If freet - root createdecor create or சி Tre milli Tre curent et Alle (current til) IF .core, furent curat. Bert (re) mata Tortur. retwee wete dat er create that there IF .co .cle) rent.eft created le predete 7 2 13. Assume the tree on Figure 2, modified in steps 11 - 12 (if appropriate), is an AVL tree and we want to check if it is balanced. Sketch a current version of tree (after previous steps) in the empty space below and calculate balance factor for each node. Is the tree Well-balanced? (4 points)
CPS2232 Final Exam Spring 2022 12. Assume the tree on Figure 2modified in step 11 (if appropriate), is a BST and we want to insert number -38" in it. What is the output of our free.insert(34/7 Trace the code above. You can Sketch a tree in the emply square below and visually explain using this tree how the insertion was performed step by step Output: (3 points) powiat By te tre mesta (E) If freet - root createdecor create or சி Tre milli Tre curent et Alle (current til) IF .core, furent curat. Bert (re) mata Tortur. retwee wete dat er create that there IF .co .cle) rent.eft created le predete 7 2 13. Assume the tree on Figure 2, modified in steps 11 - 12 (if appropriate), is an AVL tree and we want to check if it is balanced. Sketch a current version of tree (after previous steps) in the empty space below and calculate balance factor for each node. Is the tree Well-balanced? (4 points)