def performanceAVL(): """Demonstrate AVL properties always hold by building and deconstructing AVL trees from scratch.""" n = 4 while n <= 1024: bt = BinaryTree() added = [] for i in range(n): new = i if not new in bt: bt.add(new) added.append(new) if not bt.root.assertAVLProperty(): print(bt) assert False random.shuffle(added) for i in added: bt.remove(i) if (bt.root): if not bt.root.assertAVLProperty(): print(bt) assert False assert i not in bt print("pass " + str(n)) n *= 2
import random from adk.avl import BinaryTree """ Generate numerous trees of size n and determine range of heights in the AVL trees. Not definitive, but indicative of the minimum & maximum height of an AVL tree given n nodes """ for n in range(1, 511): minH = 999 maxH = 0 for _ in range(1000): bst = BinaryTree() for i in range(n): val = random.randint(1, 100000) bst.add(val) if bst.root.height < minH: minH = bst.root.height if bst.root.height > maxH: maxH = bst.root.height print(n, minH, maxH)
def setUp(self): self.bst = BinaryTree()