Representing trees

Published

2023-08-05

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?

Three Representations

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

  1. A data structure that is well-suited to sparse graphs like trees is _____________________.
  2. A data structure that is well-suited to dense graphs is _____________________.
  3. With a binary tree all we need are pointers to __________ and ___________ children, to represent our data.
  4. In an adjacency matrix, if we take a column or row sum, this equals the _______________ of the corresponding node.
  5. 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ɐ

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.