Search
In this problem, we present a few characteristics of rooted binary trees. First, let us introduce some notation:
Subsequently, we define eight characteristics of nodes and/or (sub)trees:
Finally, we present a recursive specification of a pseudo-random binary tree.
There is a 9-tuple of non-negative integers (LA, RA, M, C0, C1L, C1R, S, D, Rkey), where C0 ≤ C1L ≤ C1R ≤ S. The left and right children of each node n and their keys are defined as follows:
You are given a 9-tuple (LA, RA, M, C0, C1L, C1R, S, D, Rkey) defining binary tree T and one of the eight characteristics given above. Depending on the characteristics, denoted by one of integers 1, 2, 3, 4, 5, 6, 7, 8, calculate the corresponding value:
Your code will be evaluated on 8 test cases. Each test case tests different charactersitics described above. Each test case consists of 4 separate tests performed on random trees (randomly generated 9-tuple). Each of the 8 test cases will grant you 0.5 points if all 4 tests pass. There is time limit 1 second for each test.
Below is a basic code structure you can use. Copy-paste the following code and complete the solve function according to the description above. Then submit your final main.py.
solve
main.py
def solve(tree_params, characteristics): """ >>> solve((13, 10, 29, 4, 10, 15, 28, 4, 7), 2) 40 >>> solve((11, 19, 29, 6, 13, 20, 30, 5, 14), 3) 4 """
__ 7____ 28 __26______ 1 __ 3____ __ 1 __ 3 13 1
>>> solve((13, 10, 29, 4, 10, 15, 28, 4, 7), 2) 40
__________________14______________ __10________________ ___________*12__________ _*27 _______*15 18____ _______*10 15 ____10____ __ 8____ 27____ __27__ __15__ 8 __27__ __18__ 15 18 10 12 15 18 26 8
>>> solve((11, 19, 29, 6, 13, 20, 30, 5, 14), 3) 4