Expression Tree
Intro
This article is for the Expression Calculator, make sure to play around with that so that the article makes sense.
I’ve been learning mathematical proofs by learning from first-principles. The concept of the tree structure came up when learning about subsets. That was pretty interesting on its own, but when I started learning about logical operations, it was getting a little bit complicated to visualize. So, I decided to write code to make a tree so that I can get a better understanding of it. But, after I realized that I’d have to make a parser, I thought it would be better to start out by doing it for something simpler like numbers. While doing that, I thought it wouldn’t be complete without variables, so that got added too. I’m working on a logical expression calculator and a few others as well, they’ll all be released soon!
Intro to the Expression Tree
The expression tree is a structural representation of an expression. An expression is some numbers and variables being joined together in many ways with operators, like a + b
or 5 * x
. Every expression can be shown as a tree. Why does this matter? The tree isn’t only a different way of writing an expression, but it’s also a data structure. Using the tree structure is helpful for computation. But that’s not all, theres also some magical things we can do with this structure.
This article is made up of 10 mini-articles, but I’ve divided it into 2 sections, the first one is about the visualization of the tree, and the second one is about the code. All the code for this project is open-source on github
Go To: