#1,175 – An Example of an Expression Tree

You can assign a lambda expression to an instance of an expression tree so that you then have the corresponding expression represented as a data structure.  Below is an example of how an expression is represented in an expression tree.

Suppose that we have the expression for converting Fahrenheit to Celsius, as:


We create an expression tree by decomposing the expression into a left side, operator and right side.  We then further decompose for any sub-expression that can be decomposed.  The resulting tree looks as follows:


We can interpret the expression tree as follows:

  • Main expression: (f – 32) * 5 / 9
    • Left: (f – 32) * 5
      • Left: (f – 32)
        • Left: f
        • Operator: –
        • Right: 32
      • Operator: *
      • Right: 5
    • Operator: /
    • Right: 9



About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: