Skip to main content

AVL

AVL represents a self balancing binary tree where the heights of the two child subtrees of any node differ by at most one. Instantiate an empty Avl tree below

Usage

Avl(comparator: Callable = lambda x, y: x >= y)

Parameters:
      comparator : Callable
            A lambda function to relatively order the items in the Avl tree
            Comparators should be defined in the following format: (x, y) => x >= y

Methods

MethodDescription
searchSearch for an item in the tree
insertInsert an element into the tree
deleteDelete an element from the tree
minFind the smallest element in the tree
maxFind the largest element in the tree
successorFinds the next biggest element after "item"
predecessorFinds the next smallest element after "item"
rankFinds the rank of a particular item
selectGiven the rank, find the associated item
in_orderConduct an in order traversal of the tree and output the result in a list
pre_orderConduct a pre order traversal of the tree and output the result in a list
post_orderConduct a post order traversal of the tree and output the result in a list
printPrints the type of traversal

Example

from jellybeans.structures import Avltree = Avl(lambda x,y: len(x) >= len(y))