From: Davis on
"Yersinio Jimenez" <yersinioj(a)hotmail.com> wrote in message <hckg5o$8t6$1(a)fred.mathworks.com>...
> Hi every guys.
>
> Does any one know if there is some tree like data structure in MatLab?
>
> The questions is because some algorithms are more clear if you think in terms of tree data structure instead of matrix.
>
>
> Thanks in advance.
> Yersinio.

I couldn't find a 'tree' class either, although I've looked. However, it should be possible to spin your own by implementing it using an object oriented approach. Here, you create a 'node' class (preferably inherited from the handle class), with a constructor and destructor, and properties that include links to other nodes. You then create a 'tree class' that inherits the properties of the node class and include methods for inserting and deleting nodes, one to walk the tree up and down from its root, etc. You could also include events and event listeners if the application calls for it.

In principle this could be implemented using structures (although I wouldn't even want to try, since using the object oriented class-based approach would be much, much easier). (Honesty alert: I haven't actually done this yet, but am working on it.) Comments welcome.
From: Derek O'Connor on
"Yersinio Jimenez" <yersinioj(a)hotmail.com> wrote in message <hckg5o$8t6$1(a)fred.mathworks.com>...
> Hi every guys.
>
> Does any one know if there is some tree like data structure in MatLab?
>
> The questions is because some algorithms are more clear if you think in terms of tree data structure instead of matrix.
>
>
> Thanks in advance.
> Yersinio.
-------------------------------------------------------------------

The simplest tree data structure is an array of parent 'pointers'

A tree with n nodes can be stored using two arrays : Node(1:n)
stores node data such as name, geographical coordinates, etc.,
and Parent(1:n), where Parent(i) contains an number in (1:n)
which is the location of node i's parent in array Node(1:n).

Example: Tree with 14 nodes labelled with letters of the alphabet

1 2 3 4 5 6 7 8 9 10 11 12 13 14
--------------------------------------------------------
Node: y q g s t e k w l x y v f m
Parent: 8 4 2 0 4 4 12 6 8 7 8 13 8 3

The root of the tree is Node(4) = s because Parent(4) = 0.

This data structure is fine if all you want to do is climb up the tree, otherwise you need a more complicated data structure. If you don't need node data omit array Node(1:n).

Read Cormen, Leiserson, and Rivest : Intro. to Algorithms, or Aho and Ullman: Foundations of Computer Science

Derek O'Connor
 | 
Pages: 1
Prev: histc
Next: medfilt1 vs medfilt2