Question DSA-BST-0013
MediumWhat is the output of this code?
class Node:
def __init__(self, v, l=None, r=None):
self.v, self.l, self.r = v, l, r
def insert(n, v):
if not n:
return Node(v)
if v < n.v:
n.l = insert(n.l, v)
else:
n.r = insert(n.r, v)
return n
root = None
for v in [50, 30, 70, 20, 40, 60, 80]:
root = insert(root, v)
def ino(n):
return [] if not n else ino(n.l) + [n.v] + ino(n.r)
print(ino(root)[])
- A.
60
- B.
50
- C.
Sign up free to see the answer and a step-by-step explanation.