Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing a code for AVL trees. Below is the code outline and what needs to be done. IGNORE THE getBFSITERATOR METHOD. import

I need help writing a code for AVL trees. Below is the code outline and what needs to be done. IGNORE THE getBFSITERATOR METHOD.

import java.util.Iterator;

public class AVLTree implements StringTree{

private class AVLNode{

//Do not change these variable names

String key;

String value;

AVLNode left;

AVLNode right;

//Place any additional fields you need here

//TODO implement the node class here

}

//Use this variable as your root

AVLNode root;

//You may use any additional fields here as you see fit

public void makeEmpty() {

// TODO Remove all elements from the AVL tree.

}

public int size() {

// TODO Return the number of elements currently in the tree.

return 0;

}

public void insert(String key, String value) {

// TODO Insert the pair into the AVLTree

// Throw an IllegalArgumentException if the client attempts to insert

public boolean insert (T x){

try {

root = insert (x, root);

countInsertions++;

return true;

} catch(Exception e){

// TODO: catch a DuplicateValueException instead!

return false;

}

}rt a duplicate key

}

public String find(String key) {

// TODO Return the value affiliated with the String key.

// Throw an ObjectNotFoundException if the key is not in the AVLTree

return null;

}

public Iterator getBFSIterator() {

// TODO Only complete this section if you wish to attempt the 10 points EC

// This function should return a BFSIterator: Starter code provided below

return null;

}

/* Define your private Iterator class below.

private class BFSIterator implements Iterator{

public boolean hasNext() {

// TODO Return true if the iterator has another value to return

return false;

}

public String next() {

// TODO Return the next value in a BFS traversal of the tree

// It should start at the root and iterate through left children before right

return null;

}

}

*/

}

//AVL TESTER CLASS

public abstract class AVLTester {

public static boolean verifyAVL(StringTree toTest){

// TODO Return true if toTest is an AVL implementation of a String tree and false otherwise.

// All StringTree interface methods must behave correctly

// You may assume that size() and isEmpty() return the correct values

// Other than this, do not assume anything about the tree toTest, including its start size.

return false;

}

// You may use as many static helper functions as you think are necessary

}

//STRING TREE CLASS

import java.util.Iterator;

public interface StringTree {

public void makeEmpty();

public int size();

public void insert(String key, String value);

public String find(String key);

public Iterator getBFSIterator();

}

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Write to groups, gatekeepers and the universe

Answered: 1 week ago

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago