Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Implement AVL trees that allows both iterative traversal and recursive traversal.

Iterative traversal is fairly easy if null left and right values in nodes are replaced by references to other nodes. A neighbor link is a link from a tree node to an inorder predecessor or successor that is not a descendant of the node. Note that if a node has a left child, the inorder predecessor will be that child or the rightmost descendant of that child (and thus a descendant of the node). By symmetry, if a node has a right child, the node's inorder successor will be that child or the leftmost descendant of that child.

So in a binary search tree with neighbor links, every link field that does not point to another node contains a neighbor link to the node's inorder predecessor (if it's a left link) or inorder successor (if it's a right link). The left link field of the node with no inorder predecessor contains a null neighbor link, as does the right link field of the node with no inorder successor.

Your AVL class

Define a class AVLTree with a private inner class AVLNode to represent tree nodes using neighbor links where appropriate. Your class to be parametrized as in the Weiss text. However your AVLTree is to have instance variables for the tree size and for a comparison counter, as well as for the root.

Your AVLNode class is to have six instance fields representing the node's data value, its two children, flags for each subtree, and the height of the tree rooted at the node.

Your AVLTree class is to have at least the following public constructors and methods:

  • A zero-argument constructor that constructs an empty AVL tree.
  • A constructor that takes an appropriately parametrized Collection, and constructs a tree containing all of the members of the collection.
  • A method insert that takes an element of the appropriate type and inserts it into the AVL tree. The resulting tree is to be an AVL tree. The return type is to be void. The tree size should be updated if and only if the insertion succeeded. Attempts at duplicate insertions or insertions of null values should be handled by throwing an IllegalArgumentException with an appropriate error message. Note that this exception class is already defined.
  • A zero-argument method height that returns the height of the tree as an int
  • A zero-argument method size that returns the number of elements of the tree (as an int)
  • Two methods getCounter() and resetCounter() that respectively return the value of the tree's counter, and set it to 0
  • Four zero-argument methods for traversal, each of which returns an appropriately parametrized List of the tree members, in sorted order or reverse sorted order. Specifically, you are to define
    • a method traverse that works recursively and returns a List of the tree's data items in sorted order
    • a method traverseInReverse that works recursively and returns a List of the tree's data items in the reverse of sorted order
    • a method iterativeTraverse that works by repeatedly finding inorder successors. This method is to return a List of the tree's data items in sorted order.
    • a method iterativeTraverseInReverse that works by repeatedly finding inorder predecessors. This method is to return a List of the tree's data items in the reverse of sorted order.

Java, Programming

  • Category:- Java
  • Reference No.:- M9716463
  • Price:- $25

Priced at Now at $25, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As