how is data in a tree stored in memory?
Usually it's stored as an adjacency list. Which is basically a linked list for every single node. So the linked list of a node u contains every node v such that (u,v) is a valid edge of the tree. 


The adjacency list of this tree would be:

 1 -&gt;
 3 -&gt; 1, 4
 4 -&gt;
 5 -&gt; 3, 8
 7 -&gt; 
 8 -&gt; 7, 10
10 -&gt;


It can also be stored using an adjacency matrix. But that's used when the nodes of the tree are less (since it requires more memory). Adjacency list is better for sparse graphs.