Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java ------Binary-sort tree Problem Description: The problem to be solved is the building of a binary tree in RAM using methods that recursively call themselves

Java ------Binary-sort tree

Problem Description:

The problem to be solved is the building of a binary tree in RAM using methods that recursively call themselves to construct the tree. If the values are stored correctly, they can be retrieved in numeric order by merely traversing the tree and checking the values for numeric order. It is not the worlds best sort algorithm but it has two points in its favor: (a) it can be used to insert values that occur leisurely but that can be retrieved in numeric order at a moments notice, and (b) it will give you some practice using recursion.

The program will have 3 classes; (1) the class containing the main method, (2) a class named treeSort and (3) a class named node. Objects of the node class will be used as nodes in the sort-tree while an object of the treeSort class will receive long integer numeric values and create nodes to contain them in the tree. You can think of the tree as a two-dimensional linked-list and like any linked list, it exists in RAM but is built dynamically. The main method will generate the random values and send them to the sortTree by calling a method.

SortTree will then have at least four methods:

public boolean insert(long value)

This method will be called by main and will insert the value into the tree. If the value to be inserted is a duplicate of one already in the tree, the insertion will be terminated without any node being created and the value true will be returned to the caller. Otherwise insert will return the value false.

public long [] retrieve( )

This method will create an array of type long and will fill it with the values in sorted order from the tree. Since the insert method can count the number of values currently in the tree, creating the array should be able to use this value to size the array exactly.

public boolean isPresent(long value)

This method will search the tree for the argument value and if found, will return true If the value is not found, false will be returned.

public int getCount( )

This method will return the number of values currently in the tree. It will count only the actual values, not the duplicates for which insert returned false.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Explain the paging function of a cellular system.

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago