Trevor Elkins
Published on
/
2 min read

Trees are everywhere

Trees are the often the first data structure students struggle to intuitively understand. Lists and arrays are simple enough if you've ever shopped for groceries before. If you've stood in line at the grocery store then you grasp a queue. And if you've played cards then you are familiar with a stack. But trees are a bit more abstract. I was one of those students.

It turns out trees are actually very intuitive, we just learn terrible examples for them and jump straight into the weeds of implementing red-black trees and AVL trees.

To give you an example, the entire web is based on trees. Those React nodes that you're writing? They all end up having a common root node and form a tree (the DOM). The Javascript you're writing in your editor? That too is converted to an abstract syntax tree to be interpreted. And the file you saved your code in? The file system is a tree too.

Before you stop to correct me, there is an important distinction between formal academic trees and the trees I'm talking about. For example, balanced trees are useful because of their specific properties and constraints and should definitely be learned. My point is that we often learn about trees in the wrong order. We should start with the trees we already know and then move on to the more complex ones.