Tree Structures
14.7.1. Tree Structures#
Let’s look at an example of a comment with replies, and replies to those replies, etc. (this could be on twitter or any other social media system):
Seeing comments and replies like this is hopefully familiar to you.
Let’s look at this organized in a different organization, which is called a “tree” structure in programming and in math:
In the “tree” structure, each comment or reply is called a “node,” with the initial comment being the “root node.” Each of these nodes has lines showing which nodes are replies (in math terminology the replies are “children”).
So given this tree structure, how do we represent it in code, and how do we navigate it?