Implement avl tree

Assignment Help JAVA Programming
Reference no: EM13746

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: EM13746

Questions Cloud

Define a suitable functional unit : Define a suitable functional unit for a comparative study between two different types of paint.
Technical community blog : Write a blog article for a coding/technical community blog
Distributed random variables : Daily Airlines fies from Amsterdam to London every day. The price of a ticket for this extremely popular flight route is $75. The aircraft has a passenger capacity of 150.
Compute the transfer function : In this project we will consider the control of a synchronous generator supplying electricity to the grid.
Implement avl tree : Implement AVL trees that allows both iterative traversal and recursive traversal.
Memory allocation in operating system : Analysis and implementation of algorithms for memory allocation in operating system, Explain First- t and best- t methods are used in memory allocation in operating systems.
Development of the current strategic potential of airline : Evaluate the organisation's current external and internal strategic position
Ethics and social responsibility : Ethics and social responsibility at McDonalds
Write a paper on memory management : Write a paper on Memory Management

Reviews

Write a Review

JAVA Programming Questions & Answers

  Design a course registration system

Create an application which represents a simplified course registration system using ArrayLists and HashMaps.

  Cascading style sheet to a website

Compare and contrast the process of adding JavaScript and a Cascading Style Sheet to a Website. Determine if they can be used simultaneously in a page.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a java program

UserApp and PrettyPrintUtility multiple times (supplying different TransData test file names), the AutoTesterUtility PROGRAM will be the driver program.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  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.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  The frantic pipe layer game

Design the Frantic Pipe Layer game

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

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