Largest Smaller BST Key #127
Replies: 1 comment
-
`########################################################## CODE INSTRUCTIONS:1) The method findLargestSmallerKey you're askedto implement is located at line 30.2) Use the helper code below to implement it.3) In a nutshell, the helper code allows you toto build a Binary Search Tree.4) Jump to line 71 to see an example for how thehelper code is used to test findLargestSmallerKey.########################################################## A nodeclass Node: Constructor to create a new nodedef init(self, key): A binary search treeclass BinarySearchTree: Constructor to create a new BSTdef init(self): def find_largest_smaller_key(self, target):
Given a binary search tree and a number, inserts anew node with the given number in the correct placein the tree. Returns the new root pointer which thecaller should then use(the standard trick to avoidusing reference parameters)def insert(self, key):
######################################### Driver program to test above function######################################### bst = BinarySearchTree() Create the tree given in the above diagrambst.insert(20) result = bst.find_largest_smaller_key(17) print ("Largest smaller number is %d " %(result)) ` |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions