8. sum_binary_tree For this function, we are using a data structure called a binary tree, which is useful for storing all different kinds of data. In this problem a binary tree contains a single...


8. sum_binary_tree<br>For this function, we are using a data structure called a binary tree, which is useful for storing all different kinds of data.<br>In this problem a binary tree contains a single number, and it has two children, each of which may be either None, or<br>they may be more binary trees. You can see, this is a recursively defined data structure!<br>To recap: each binary tree contains a number and two children. The children are either None or a BinaryTree object.<br>In this function we want to sum up all of the numbers contained in a binary tree and its children (recursively).<br>Sample calls should look like this:<br>| >>> sum_binary_tree(BinaryTree(10, None, None))<br>10<br>>>> sum_binary_tree(BinaryTree(10, None, BinaryTree(10, None, BinaryTree(10, None, None))))<br>30<br>>>> sum_binary_tree(None)<br>

Extracted text: 8. sum_binary_tree For this function, we are using a data structure called a binary tree, which is useful for storing all different kinds of data. In this problem a binary tree contains a single number, and it has two children, each of which may be either None, or they may be more binary trees. You can see, this is a recursively defined data structure! To recap: each binary tree contains a number and two children. The children are either None or a BinaryTree object. In this function we want to sum up all of the numbers contained in a binary tree and its children (recursively). Sample calls should look like this: | >>> sum_binary_tree(BinaryTree(10, None, None)) 10 >>> sum_binary_tree(BinaryTree(10, None, BinaryTree(10, None, BinaryTree(10, None, None)))) 30 >>> sum_binary_tree(None)

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here