Posts

Showing posts from April, 2023

EVALUATE EXPRESSION TREE

Image
Problem - All leaf node in the tree are operands, always positive number. All the other nodes represents operator. -1 represents addition -2  : subtract -3 : division -4 : product APPROACH : think about base case. If you are on leaf node then return.     i.e. if tree.value > 0 : return the value .     next simply get the left tree value and right tree value and apply the operand respectively using recursion.      solution evaluation expression tree