This while loop doesn 't run for more than 2 times  as there can be at max. two children of a node
while ( child != 0 ) : NEW_LINE INDENT lcaWalk ( child , q , m , subsets ) NEW_LINE unionSet ( subsets , u , child ) NEW_LINE subsets [ findSet ( subsets , u ) ] . ancestor = u NEW_LINE child = subsets [ child ] . sibling NEW_LINE DEDENT subsets [ u ] . color = BLACK NEW_LINE for i in range ( m ) : NEW_LINE INDENT if ( q [ i ] . L == u ) : NEW_LINE INDENT if ( subsets [ q [ i ] . R ] . color == BLACK ) : NEW_LINE INDENT print ( " LCA ( % d ▁ % d ) ▁ - > ▁ % d " % ( q [ i ] . L , q [ i ] . R , subsets [ findSet ( subsets , q [ i ] . R ) ] . ancestor ) ) NEW_LINE DEDENT DEDENT elif ( q [ i ] . R == u ) : NEW_LINE INDENT if ( subsets [ q [ i ] . L ] . color == BLACK ) : NEW_LINE INDENT print ( " LCA ( % d ▁ % d ) ▁ - > ▁ % d " % ( q [ i ] . L , q [ i ] . R , subsets [ findSet ( subsets , q [ i ] . L ) ] . ancestor ) ) NEW_LINE DEDENT DEDENT DEDENT return NEW_LINE