# Project 1 Question 5-a - Python # Created by Ryan Doherty # (a) (5 points) # Use your recursive implementation of your BST and your iterative implementation of your AVL Tree from Parts 1 and 2 to construct trees using getRandomArray(10,000). import question_1_c as BST # Recursive BST import question_4_c as AVL # AVL Tree import question_3_a as RA # getRandomArray arr = RA.getRandomArray(10000) AVL = AVL.Node(None) BST = BST.Node(None) for n in arr: BST.insertRec(n) AVL.insertIter(n) print("Trees sucessfully created!")
# Project 1 Question 6-c - Python # Created by Ryan Doherty # (c) (5 points) (You must submit code for this question!) Construct a BST and AVLTree iteratively using getSortedArray(10000). Compare how many levels we have to traverse in the two trees. You can include a screenshot of your code’s output or write it out by hand. import question_1_d as BST # Iteritive BST import question_4_c as AVL # AVL Tree import question_3_b as SA # getSortedArray def createTree(tree): for n in arr: tree.insertIter(n) return tree arr = SA.getSortedArray(10000) avl = createTree(AVL.Node(None)) print("The traversals of the AVL is:", avl.traversals) bst = createTree(BST.Node(None)) print("The traversals of the BST is:", bst.traversals)
tree.deleteIter(n) return tree avl_time = [] bst_time = [] beforeTime = time.perf_counter() arr = RA.getRandomArray(10000) print("Time to generate array:", time.perf_counter() - beforeTime, "ms") beforeTime = time.perf_counter() bst = createTree(BST.Node(None)) bst_time.append(1000 * (time.perf_counter() - beforeTime)) print("The time to complete the BST is:", bst_time[0], "ms") beforeTime = time.perf_counter() avl = createTree(AVL.Node(None)) avl_time.append(1000 * (time.perf_counter() - beforeTime)) print("The time to complete the AVL is:", avl_time[0], "ms") beforeTime = time.perf_counter() bst = deleteTree(BST.Node(None)) bst_time.append(1000 * (time.perf_counter() - beforeTime)) print("The time to delete the BST is:", bst_time[1], "ms") beforeTime = time.perf_counter() avl = deleteTree(AVL.Node(None)) avl_time.append(1000 * (time.perf_counter() - beforeTime)) print("The time to delete the AVL is:", avl_time[1], "ms")