Hi I\'m stuck doing this, not sure how to go about it.
If I have two binary trees, how would I check if the have the same shape? Data in the nodes doesn\'t matter, j
Just follow the branches, mimicking each move in one tree in the other. In Python pseudo-code:
class Tree:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def same_shape(T1, T2):
if T1 == None:
return T2 == None
if T2 == None:
return T1 == None
return same_shape(T1.left, T2.left) and same_shape(T1.right, T2.right)