Note that the below two lines can also be this - subsets [ node . data ] . child = node . right . data ; subsets [ node . right . data ] . sibling = node . left . data ; This is because if both left and right children of node - ' i ' are present then we can store any of them in subsets [ i ] . child and correspondingly its sibling
subsets [ node . data ] . child = node . left . data NEW_LINE subsets [ node . left . data ] . sibling = node . right . data NEW_LINE elif ( ( node . left != None and node . right == None ) or ( node . left == None and node . right != None ) ) : NEW_LINE if ( node . left != None and node . right == None ) : NEW_LINE INDENT subsets [ node . data ] . child = node . left . data NEW_LINE DEDENT else : NEW_LINE INDENT subsets [ node . data ] . child = node . right . data NEW_LINE DEDENT