View on GitHub

@tree

A MATLAB class to represent the tree data structure.

Download this project as a .zip file Download this project as a tar.gz file

A simple tree data structure in a MATLAB class.

This page serves as a basic documentation or tutorial for the @tree class. We duplicate some of the information that can be found in the help sections of methods, so that you can find almost everything here, in one place.

But here is a short primer: the tree class is simple, and it is not a handle class. It is very simple, so you will find no Node class, no complicated path search, no fancy imports, etc... It is all based on plain MATLAB arrays and cell arrays, with no or extremely small overhead.

Also, it is not inheriting from handle, which means that it is a standard 'per value' object, and cannot be modified or accessed 'per reference'. This generates some apparent weirdness if you are used to the Java counterparts, but also some flexibility, that we detail later.

Each method is normally documented, and you can access its documentation using the classical

>> help tree/findpath

for instance. These pages add a tutorial that aims at familiarizing yourself with the class as a whole.

Tutorial.

This tutorial is split into several sections, normally independent. It is a good idea however to read them in order:

  1. Introduction to trees, the tree class, and basic information.
  2. Creating, modifying and accessing a tree.
  3. MATLAB operators for trees.
  4. Special trees and methods.
  5. Searching a tree.
  6. Tree traversal.
  7. Plotting a tree.

Wrapping up.

This rather long tutorial shows a glimpse of what you can do with the tree class, and hopefully will start you using it for your needs. Do not hesitate to contact me if you see obvious missing functionalities. Here is a list of what could be done extra:

The tree class has a very small memory overhead, by construction, and should be rather memory efficient. But it was not designed for speed performance: a large number of methods are written using recursion and involve array copying. New, better performing implementations of these methods would be beneficial.