How can we represent Trees? ### Edge List We can use an **edge list** as one form of representation of a tree. ![](Screen%20Shot%202021-04-15%20at%208.26.06%20AM.png) Pros: * Very fast to iterate over, cheap to store Cons: * storing a tree in a list lacks the structure to efficiently query all the neighbors of a node ### Adjacency List ![](Screen%20Shot%202021-04-15%20at%208.29.58%20AM.png)] In this representation we store a mapping between a node and all of its neighbors. For example, above we see that node 4 has neighbors 1, 5 and 8, and node 4 is mapped to that neighbor. ### Adjacency Matrix We can also store a tree as an adjacency matrix of size $N x N$ (where we have $N$ nodes in the tree): ![](Screen%20Shot%202021-04-15%20at%208.30.54%20AM.png) In practice this is rarely done because it is a *huge* waste of space! --- Links to: [Trees](Trees.md)