Question DSA-TREE-0043
MediumWhat is the output of this code?
class N:
def __init__(self, v, l=None, r=None):
self.v, self.l, self.r = v, l, r
def height(n):
return 0 if n is None else 1 + max(height(n.l), height(n.r))
t = N(1, N(2, N(4, N(8))), N(3))
print(height(t))
- A.
3
- B.
4
- C.
5
- D.
2
Sign up free to see the answer and a step-by-step explanation.