Implement avl trees that allows both iterative traversal

Assignment Help JAVA Programming
Reference no: EM13346846

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.

Reference no: EM13346846

Questions Cloud

Part -1 consider the product paint1identify a suitable : part -1 consider the product paint1.identify a suitable functional unit for a stand alone study on paint.2.define a
Write a blog article for a codingtechnical community : write a blog article for a codingtechnical community blog.the theme is general c or java. choose any subject under this
1 daily airlines fies from amsterdam to london every day : 1. daily airlines fies from amsterdam to london every day. the price of a ticket for this extremely popular flight
In this project we will consider the control of a : in this project we will consider the control of a synchronous generator supplying electricity to the grid. we will
Implement avl trees that allows both iterative traversal : implement avl trees that allows both iterative traversal and recursive traversal.iterative traversal is fairly easy if
Analysis and implementation of algorithms for memory : analysis and implementation of algorithms for memory allocation in operating systemexplain first-t and best-t methods
The increasing need to travel and lifestyle changes of : the increasing need to travel and lifestyle changes of society has made airlines industry one of the most demanded and
Write a paper on mcdonaldsethics and social responsibility : write a paper on mcdonalds.ethics and social responsibility at mcdonaldspaper includesabout mcdonaldscorporate social
Memory managementwrite a paper to provide depth knowledge : memory managementwrite a paper to provide depth knowledge of how memory is used in executing your programs and its

Reviews

Write a Review

JAVA Programming Questions & Answers

  In this game we have a number of players interacting in a

in this game we have a number of players interacting in a simple way. the game takes place on a virtual

  Using a link list implementation

Using a link list implementation, simulate the war car game. The program should read an input of several line of card values and output the winner and the number of rounds it takes.

  Determines the surface area and volume of a hemisphere

Write an application that reads determines the surface area and volume of a hemisphere and then calculates the radius given a surface area and volume.The first step is to read in the radius from the users and then calculate the surface area and vo..

  Powerful pain reliever are consumers with headaches

Your target market for the most powerful pain reliever are consumers with HEADACHES. Start with goals and objectives. Do a SWOT. What information is most important for your market? Do some market research.

  Write java program to receive input and displayed interest

Write a Java program that receive some input and displayed the interest. Format the number into 2 decimal places. Using loop is an advantage.

  Write down java console application to add new student

Write down java console application presents the following menu. Add new student and scores in Biology, Physics and chemistry Search for a given student.

  Ask the user to input a grade (integer from 1-100)

Program should still ask the user to input a grade (integer from 1-100) and then output the letter grade.  Scale:  Greater than 90 is an "A"; Greater than 80 to 90 is a "B", Greater than 70 to 80 is a "C", Greater than 60 to 70 is a "D", and 60 or le..

  Multiple choice java programming questions

Determine which of the following may be a violation of information hiding if inserted for the comment above?

  World data app

Prepare WorldDataApp project. It implements the NameIndex portion, including creating it in SetupProgram, and searching, viewing and updating it in UserApp program.

  How to link different classes forms

How to link different classes forms. When a person clicks on A, B, or C the program will go to the addEmployee form or Punch In/Out form in Java.

  Write a class array that encapsulates an array

Write a class Array that encapsulates an array and provides bounds-checked access. The private instance variables should be int index and inarray[10]. The public members should be a default constructor and methods (signatures shown below) to provide ..

  Menu based program to maintain student records

Write a menu based program to maintain student records. Your program should take the following inputs: 1. Student first name (max. 20 characters) 2. Student last name, (max. 20 characters) 3. Student scores (float/double), eg. 85.4 Problem

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd