# 4.4. Quiz

## Interpretation

* Explain how the `remove()` method works in the [`AbstractBalancedBinarySearchTree`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/tree/balanced/AbstractBalancedBinarySearchTree.java) class:
  * Explain what gets assigned to `lowest` in [`L71`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/tree/balanced/AbstractBalancedBinarySearchTree.java#L71).
  * Explain how the `balance()` methods in [`AVLTree`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/tree/balanced/AVLTree.java) and [`RedBlackTree`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/tree/balanced/RedBlackTree.java) keep the trees balanced (or fails to keep them balanced) after a removal.
* Write a report including your explanation and save it as `quiz4.pdf`.

## Implementation

* Create the [`BalacnedBinarySearchTreeQuiz`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/tree/balanced/BalancedBinarySearchTreeQuiz.java) class under the [`tree.balanced`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/tree/balanced) package that inherits [the`AbstractBalancedBinarySearchTree`](https://github.com/emory-courses/dsa-java/blob/master/src/main/java/edu/emory/cs/tree/balanced/AbstractBalancedBinarySearchTree.java) class.
* Override the `balance()` method that first checks the following conditions:
  * `node` is the only child &
  * `node`’s parent is the right child of `node`'s grand parent &
  * `node`’s uncle has only one child.
* If all of the above conditions are satisfied, `balance()` makes multiple rotations such that the left subtree is always full before any node gets added to the right subtree.
* For the example below, after adding the keys (in red) to the trees `1`, `2`, `3`, and `4`, they all need to be transformed into the tree `5` by the `balance()` method.
* The transform must be performed only by rotations; other setter methods such as `setLeftChild()` or `setRightChild()` are not allowed in this assignment.

![](/files/-MIubC4iV14KhiZuedMD)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emory.gitbook.io/dsa-java/binary-search-trees/exercises.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
