Maximum of a General Tree X37904


Statement
 

pdf   zip   tar

thehtml

Write a program that reads a non-empty tree of integer numbers and writes its maximum value. Your program should extend the class Tree implemented in file simple_tree.py in the public files section of the problem statement, which can be downloaded by clicking on the ’cat’ icon.

For example, given the following specification of a tree in pre-ordre, where the value stored at each node is followed by its arity

Input

1 4
  3 2
      6 0
      -6 0
  12 0
  2 4
     3 0
     5 2
       10 0
       -13 0
     11 0
     7 0
  8 0

Your program should write Output

12

Hint

Extend the class Tree in file simple_tree.py with a new method maxim with the following header

def maxim(self):
   ...

and call that method from main after reading the tree.

Public test cases
  • Input

    1 4
      3 2
          6 0
          -6 0
      12 0
      2 4
         3 0
         5 2
           10 0
           -13 0
         11 0
         7 0
      8 0 

    Output

    12
    
  • Information
    Author
    Language
    English
    Official solutions
    Python
    User solutions
    Python