Traversals on a Binary Search Tree

There is a binary search tree equipped with the following methods besides the usual ones:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def printLCR(node):
    if node.val == None:
        return
    printRLC(node.left)
    print(node.val)
    printRLC(node.right)

def printRLC(node):
    if node.val == None:
        return
    printLCR(node.right)
    printLCR(node.left)
    print(node.val)

The following data (in the following order) are inserted into the binary search tree:

10, 4, 17, 2, 15, 1, 6, 29, 9, 14, 13, 8, 16

If the output of print_RLC is \( a_0, a_1, \ldots, a_{12} \), compute \(\displaystyle\sum _{i=0} ^{12} {(i \times a_{i})} \).


If something is not covered, it can be asked here. Changes will be made!
×

Problem Loading...

Note Loading...

Set Loading...