Ternary Search Tree Java

Problem

Write a java program to construct and print a ternary Tree. A ternary tree is similar to a binary tree except a parent node can have up to three children instead of two. The left child value is less than the parent value, the right is greater than the parent value and the middle value is equal to the parent value.

Solution

We need to have a Node data structure that has three child nodes and one value. Populating and printing the tree can be achieved using recursive calls. For more details you can take a look at the commented source code below.

Code

Here is the code in Java

Add a Comment

Your email address will not be published. Required fields are marked *