13.5k views
1 vote
Use the implementation of AVLTreeMap and TreeMap (Java, Dython)/SearchTree (C++) provided in your textbook:

a) insert 20 sample (key, value) into an initially empty tree.
b) Delete 5 keys from the constructed AVL Tree.
c) Print height of AVL tree after each operation.
d) Print the message on output screen after each opertion is performed showing operation name and the node and key values inserted or deleted.
e) Assume keys and values are all integers.
f) Provide output of these operations in PDF that also include answers to other questions. Make sure insertions and deletions keep the AVL tree balanced by calling trinode restructuring method (implementation already provided)

1 Answer

5 votes

Final answer:

To create an AVLTreeMap, you can use the implementation provided in your textbook. Insert 20 sample (key, value) pairs and delete 5 keys from the constructed AVL Tree. Print the height of the AVL tree after each operation.

Step-by-step explanation:

Sample Solution using AVLTreeMap (Java)

To create an AVLTreeMap in Java, you can use the implementation provided in your textbook. Here is an example:

// Import the necessary packages
import java.util.*;

// Create an AVLTreeMap instance
AVLTreeMap treeMap = new AVLTreeMap<>();

// Insert 20 sample (key, value) pairs into the tree
for (int i = 0; i < 20; i++) {
treeMap.put(i, "Value " + i);
}

// Delete 5 keys from the tree
for (int i = 0; i < 5; i++) {
treeMap.remove(i);
}

// Print the height of the AVL tree after each operation
System.out.println("Height after insertions:");
System.out.println(treeMap.height());

// Print the message on the output screen after each operation
System.out.println("Insertions and deletions performed:");
for (Map.Entry<Integer, String> entry : treeMap.entrySet()) {
System.out.println(entry.getKey() + " - " + entry.getValue());
}
User Matheus Bica
by
8.1k points