1.11M Members

Help with Tertiary trees?!?!

 
0
 

:confused: I'm going to use a tertiary tree to navigate through a series of photos. This will hopefully allow someone to "walk" through these photos as if on a tour.

I was wondering if anybody had any advice on tertiary trees, do I just construct them as you would a binary tree? Do I just add another child node to the tree to make it have three children? Am I just talking nonsense?

If anybody can help me it would be greatly appreciated.

Much obliged :cheesy:

 
0
 

>Am I just talking nonsense?
Nope, those are all very good questions.

>do I just construct them as you would a binary tree?
Most likely not if what you're used to are binary search trees. The strict ordering of less than/greater than is what makes binary search trees work, and modifying that to work with three way paths typically results in a multiway tree of order 3 rather than a true tertiary tree. The first thing you need to do is figure out how to order the data so that a simple insertion algorithm can be written.

>Do I just add another child node to the tree to make it have three children?
You add another child link to each node so that the potential number of children increases to three:

class node {
  public type data;
  public node first, second, third;
}

Or, because it's almost always easier to work with an array of links instead of separate variables:

class node {
  public type data;
  public node[] link;
}

Of course, variations exist such as an ArrayList or LinkedList. You can even hardcode your own linked list operations if you want.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article