Representing trees
Now we’re ready to work with some tree search and traversal algorithms. But that brings up the question of how we represent a tree? What data structures are suitable?
Here we present how to represent a tree, including adjacency list, adjacency matrix, incidence matrix, and simple L/R object-oriented approach.
Representing trees
Note: You will not be assessed on incidence matrix.
Resources
Further reading
Comprehension check
- A data structure that is well-suited to sparse graphs like trees is _____________________.
- A data structure that is well-suited to dense graphs is _____________________.
- With a binary tree all we need are pointers to __________ and ___________ children, to represent our data.
- In an adjacency matrix, if we take a column or row sum, this equals the _______________ of the corresponding node.
- In an adjacency matrix, the complexity of finding whether or not a node is adjacent to another node is ____________ than doing so with an adjacency list. Less or greater?
Answers: ssǝl / ǝǝɹƃǝp / ʇɥƃᴉɹ ’ʇɟǝl / xᴉɹʇɐɯ ʎɔuǝɔɐɾpɐ / ʇsᴉl ʎɔuǝɔɐɾpɐ
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.