We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,878 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with Tertiary trees?!?!

: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:

2
Contributors
1
Reply
11 Hours
Discussion Span
8 Years Ago
Last Updated
2
Views
Related Article: Someone help me hate trees less is a Java discussion thread by kharri5 that has 3 replies and was last updated 8 years ago.
RichyBoomstick
Newbie Poster
2 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Narue
Bad Cop
Team Colleague
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 1.6489 seconds using 2.45MB