Evaluate Expression Tree Problem

Vivek Srivastava
Techie Delight
Nov 9, 2023

--

Given the root of a binary expression tree representing algebraic expressions, evaluate it and return its value. A binary expression tree is a binary tree, where the operators are stored in the tree’s internal nodes, and the leaves contain constants.

Assume that each node of the binary expression tree has zero or two children. The supported operators are +(addition), −(subtraction), *(multiplication), ÷(division) and ^(exponentiation).

Input:

Output: 28

Explanation: The corresponding infix notation is ((10–5)*5)+(21/7) = 28 which can be produced by traversing the expression tree in an inorder fashion.

Practice link: https://www.techiedelight.com/?problem=EvaluateExpressionTree

--

--