Skip to content

Commit c06e5ab

Browse files
committed
Add proper class description
1 parent 5e5b9a5 commit c06e5ab

5 files changed

Lines changed: 26 additions & 53 deletions

File tree

src/Containers-AVL-Tree-Tests/CTAVLTreeTest.class.st

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"
2-
An AVLTest is a test class for testing the behavior of AVL
2+
I test the AVL Tree implementation (CTAVLTree).
3+
I verify correctness of all tree operations including insertion, deletion, search, traversals, and collection protocol methods. I test edge cases like empty trees, single nodes, and complex removal scenarios.
4+
I ensure the AVL tree maintains both BST ordering property and AVL balance property through all operations, including automatic rebalancing via rotations.
5+
I test all four rotation cases and verify O(log n) height guarantees.
6+
37
"
48
Class {
59
#name : 'CTAVLTreeTest',

src/Containers-AVL-Tree/CTAVLAbstractNode.class.st

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
"
2-
AVLAbstractNode is an abstract class that represents a node in an AVL tree.
3-
4-
AVL trees are self-balancing binary search trees. This abstract node class is designed to be subclassed by concrete AVL node classes. It provides common methods and instance variables that are essential for maintaining the balance of the AVL tree.
5-
6-
Subclasses of AVLAbstractNode should implement methods for adding, removing, and manipulating nodes in the tree to ensure that the tree remains balanced.
7-
2+
I am an abstract base class for AVL Tree nodes.
3+
I define the common interface that both regular nodes (CTAVLNode) and nil nodes (CTAVLNilNode) must implement.
4+
I include protocol for AVL-specific operations like height, balance factor, and rebalancing, as well as standard tree enumeration and searching.
85
Subclasses:
9-
- AVLNilNode
10-
- AVLNode
11-
12-
Author: Milton Mamani
13-
Date: October 20, 2023
6+
- CTAVLNilNode
7+
- CTAVLNode
148
"
159
Class {
1610
#name : 'CTAVLAbstractNode',

src/Containers-AVL-Tree/CTAVLNilNode.class.st

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
"
2-
AVLNilNode is a special sentinel node used in AVL trees to represent the absence of a node.
3-
4-
In an AVL tree, `AVLNilNode` is used as a placeholder for null references, making it easier to perform tree operations without special cases for missing children. It fully implements the Null Object pattern.
5-
6-
Author: Milton Mamani
7-
Date: October 20, 2023
2+
I represent an empty node in an AVL Tree using the Null Object pattern.
3+
I provide default 'do nothing' behavior for all tree operations, eliminating the need for nil checks throughout the tree algorithms. This makes the code cleaner and prevents null pointer errors.
4+
When elements are added to me, I create and return a new CTAVLNode containing the element, effectively growing the tree. I maintain height 0 and am always balanced
85
"
96
Class {
107
#name : 'CTAVLNilNode',

src/Containers-AVL-Tree/CTAVLNode.class.st

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
"
2-
AVLNode represents a node in an AVL tree.
3-
4-
An AVL tree is a self-balancing binary search tree where the heights of the two child subtrees of every node differ by at most one. The `AVLNode` class extends the `AVLAbstractNode` class and provides the implementation of actual nodes within the AVL tree.
5-
6-
AVLNode instances hold a `contents` instance variable. These nodes are organized to keep the tree balanced, ensuring efficient operations like insertion, deletion, and search.
7-
8-
This class should not be used directly; instead use `AVLTree`.
9-
10-
Instance Variables:
11-
- contents: The value associated with this node.
12-
- left: The left child node.
13-
- right: The right child node.
14-
15-
Author: Milton Mamani
16-
Date: October 20, 2023
2+
I represent a node in an AVL Tree.
3+
I extend the functionality of a standard BST node by storing my height and performing self-balancing rotations after any modification (add or remove) to ensure the tree's height balance is maintained.
4+
The AVL invariant I maintain is: |height(left) - height(right)| <= 1
175
"
186
Class {
197
#name : 'CTAVLNode',

src/Containers-AVL-Tree/CTAVLTree.class.st

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
"
2-
AVLTree is an implementation of a self-balancing AVL (Adelson-Velsky and Landis) binary search tree.
3-
4-
An AVL tree is a binary search tree in which the heights of the two child subtrees of every node differ by at most one. This self-balancing property ensures that the tree remains approximately balanced, leading to efficient insertion, deletion, and search operations. The instances of `AVLTree` uses AVLNode to manage the overall structure of the AVL tree =,
5-
6-
`AVLTree` is a generic tree that can store comparable objects. It uses `AVLNode` instances to represent the nodes within the tree.
7-
2+
I represent an AVL Tree, a self-balancing binary search tree.
3+
I maintain the BST property (left < node < right) while also ensuring that the height difference between the left and right subtrees of any node is at most 1. This balancing act guarantees O(log n) worst-case performance for all primary operations.
4+
My public API is designed to be polymorphic with CTBinarySearchTree and includes a rich set of collection methods for enumeration, searching, and accessing.
85
Usage:
9-
To use `AVLTree`, create an instance of the class and then use the provided methods to insert, remove, or search for elements within the tree. The tree will automatically self-balance as elements are added or removed.
10-
11-
Example:
12-
```
13-
| tree |
14-
tree := AVLTree new.
15-
tree add: 41.
16-
tree add: 87.
17-
tree add: 20.
18-
tree remove: 87.
19-
tree
20-
```
21-
Author: Milton
22-
Date: October 20, 2023
6+
tree := CTAVLTree new.
7+
tree addAll: #(50 30 70 20 40 60 80).
8+
tree asArray. => #(20 30 40 50 60 70 80)
9+
tree height. => 3
10+
tree first. => 20
11+
tree includes: 30. => true
12+
tree elementsFrom: 30 to: 60. => #(30 40 50 60)
2313
"
2414
Class {
2515
#name : 'CTAVLTree',

0 commit comments

Comments
 (0)