| | |
Help with Tertiary trees?!?!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
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:
>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:
Or, because it's almost always easier to work with an array of links instead of separate variables:
Of course, variations exist such as an ArrayList or LinkedList. You can even hardcode your own linked list operations if you want.
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:
Java Syntax (Toggle Plain Text)
class node { public type data; public node first, second, third; }
Java Syntax (Toggle Plain Text)
class node { public type data; public node[] link; }
I'm here to prove you wrong.
![]() |
Similar Threads
- binary search trees (Java)
- Someone help me hate trees less (Java)
- binary trees (C)
- Trees? (C)
Other Threads in the Java Forum
- Previous Thread: calculations in java
- Next Thread: Need help Using "get and set methods"
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying page pearl print problem program programming project qt recursion scanner screen scrollbar server set size sms sort spamblocker sql string superclass swing system thread threads time tree variablebinding windows xor






