Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the templates below, create an AVL Tree Map in java (fill in the places wh

ID: 3815240 • Letter: U

Question

Using the templates below, create an AVL Tree Map in java (fill in the places where it says // fix this). In other words, create an AVL Tree which implements the Map interface. The Map interface as well as a template AVLTreeMap.java class is given below.

\Map.java Interface

\AVLTreeMap.java

public class AVLTreeMap implements Map {

class Node {
String key;
String value;
int height;
Node parent;
Node left;
Node right;
public Node(String key, String value) {
this.key = key;
this.value = value;
this.height = 1;
this.parent = null;
this.left = null;
this.right = null;
}
public int balance() {
  // fix this
return -1;
}
}

private int size;
private Node root;

public AVLTreeMap() {
  // fix this
}

public int size() {
// fix this
return -1;
}

public void put(String key, String value) {
// fix this
}

public String get(String key) {
  // fix this
return null;
}

Explanation / Answer

Ans: After fixing the code is :

public class AVLTreeMap implements Map {

class Node {

String key;

String value;

int height;

Node parent;

Node left;

Node right;

public Node(String key, String value) {

this.key = key;

this.value = value;

this.height = 1;

this.parent = null;

this.left = null;

this.right = null;

}

public int balance() {

if ( w != null )

{

w.setHeight();

if ( !w.isBalanced() )

{

w = rebalance( w );

}

}

return w;

}

return -1;

}

}

private int size;

private Node root;

public AVLTreeMap() {

{

super();

}

public AVLTreeMap(Comparator<K> comp) { super(comp); }

protected int height(Position<Entry<K,V>> p) {

return tree.getAux(p);

}

}

public int size() {

{

return elementCount;

}

else

return -1;

}

private Node put(String key, String Value ) {

if (x == null)

return new Node(key, val, 0, 1);

int cmp = key.compareTo(x.key);

if (cmp < 0) {

x.left = put(x.left, key, val);

}\

}

public String get(String key) {

AVLNode parent = null;

AVLNode target = null;

AVLNode node = root;

{

return null;

}

}