Problem 2 - Average Number of Children in a BST (20 points) Write a function getAverage Child Count(bst) that takes a bi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Problem 2 - Average Number of Children in a BST (20 points) Write a function getAverage Child Count(bst) that takes a bi
Problem 2 – Average Number of Children in a BST (20 points)
Write a function getAverageChildCount(bst) that takes a binary
search tree “bst” as input and returns the average number of
children per node, where each node may have zero, one, or two
children. (Assume that the bst is of the TreeNode type as
implemented in the attached BST.py file)
Problem 2 - Average Number of Children in a BST (20 points) Write a function getAverage Child Count(bst) that takes a binary search tree "bst as input and returns the average number of children per node, where each node may have zero, one, or two children. (Assume that the bst is of the TreeNode type as implemented in the attached BST.py file) Sample Tests/Outputs: bst = TreeNode(10) print(getAveragechildCount(bst)) bst. insert(5) bst.insert(17) print(getAverageChildCount(bst)) bst.insert(3) bst.insert(2) print(getAveragechildCount(bst)) bst.insert(8) print(getAverageChildCount(bst)) bst.insert(13) bst.insert(11) bst.insert(14) bst.insert(4) bst.insert(9) bst. insert(7) bst.insert(20) bst.insert(19) bst.insert(21) print(getAverageChildCount(bst)) . 0.6666666666666666 @.8 0.8333333333333334 8.9333333333 3333