data_structures.binary_tree.avl_tree¶
Implementation of an auto-balanced binary tree! For doctests run following command: python3 -m doctest -v avl_tree.py For testing run: python avl_tree.py
Attributes¶
Classes¶
An AVL tree doctest |
|
Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
a mirror symmetry rotation of the left_rotation |
|
A A Br |
|
|
|
A B |
|
Module Contents¶
- class data_structures.binary_tree.avl_tree.AVLtree¶
An AVL tree doctest Examples: >>> t = AVLtree() >>> t.insert(4) insert:4 >>> print(str(t).replace(” n”,”n”))
4
>>> print(str(t).replace(" \n","\n").replace(" \n","\n")) 4 2 * ************************************* >>> t.insert(3) insert:3 right rotation node: 2 left rotation node: 4 >>> print(str(t).replace(" \n","\n").replace(" \n","\n")) 3 2 4 ************************************* >>> t.get_height() 2 >>> t.del_node(3) delete:3 >>> print(str(t).replace(" \n","\n").replace(" \n","\n")) 4 2 * *************************************
- __str__() str ¶
- del_node(data: Any) None ¶
- get_height() int ¶
- insert(data: Any) None ¶
- class data_structures.binary_tree.avl_tree.MyNode(data: Any)¶
- get_data() Any ¶
- get_height() int ¶
- set_data(data: Any) None ¶
- set_height(height: int) None ¶
- data¶
- height: int = 1¶
- class data_structures.binary_tree.avl_tree.MyQueue¶
- count() int ¶
- is_empty() bool ¶
- pop() Any ¶
- print_queue() None ¶
- push(data: Any) None ¶
- data: list[Any] = []¶
- head: int = 0¶
- tail: int = 0¶
- data_structures.binary_tree.avl_tree._test() None ¶
- data_structures.binary_tree.avl_tree.left_rotation(node: MyNode) MyNode ¶
a mirror symmetry rotation of the left_rotation
- data_structures.binary_tree.avl_tree.lr_rotation(node: MyNode) MyNode ¶
A A Br
/ / /
B C LR Br C RR B A
/ –> / –> / /
- Bl Br B UB Bl UB C
/ UB Bl
RR = right_rotation LR = left_rotation
- data_structures.binary_tree.avl_tree.my_max(a: int, b: int) int ¶
- data_structures.binary_tree.avl_tree.right_rotation(node: MyNode) MyNode ¶
A B
/ /
B C Bl A
/ –> / /
Bl Br UB Br C
/
UB
UB = unbalanced node
- data_structures.binary_tree.avl_tree.t¶