예제 #1
0
    def test_bst(self):
        bst = BST()
        bst.insert(5, 6)
        bst.insert(3, 7)
        bst.insert(2, 8)
        bst.insert(4, 9)
        bst.insert(8, 10)
        bst.insert(6, 11)
        bst.insert(9, 12)

        self.assertTrue(bst.get(6) == 11)
        self.assertTrue(bst.get(15) == None)
        self.assertTrue(bst.height() == 3)
        self.assertTrue(bst.preorder() == [5, 3, 2, 4, 8, 6, 9])
예제 #2
0
def minimum_cost_tree(keys, frequencies):
    A = minimum_cost_matrix(keys, frequencies)
    bst = BST()
    create_optimal_tree(A, bst, keys, 0, len(keys) - 1)
    return bst.preorder()