Exemple #1
0
                c = int(input("Choice: "))
        except ValueError:
            print("Invalid input! Provide an integer value.")
            break

        # build bst
        if c == 1:
            print("\nBuilding binary search tree\n")
            start = time.time()
            T = buildBST(filename)
            end = time.time()

            # stats
            print("Binary Search Tree stats:\nNumber of Nodes: {}".format(
                bst.NumberOfNodes(T)))
            print("Height: {}".format(bst.Height(T)))
            print("Running time for {} construction: {}".format(
                treeType(T), end - start))

        # build b-tree
        if c == 2:
            max = int(input("Maximum number of items in node: "))
            print("\nBuilding B-tree\n")
            start = time.time()
            T = buildBTree(max, filename)
            end = time.time()

            print("B-tree stats:\nNumber of Nodes: {}".format(
                btree.NumberOfNodes(T)))
            print("Height: {}".format(btree.Height(T)))
            print("Running time for {} construction (with max_items = {}): {}".
Exemple #2
0
    option = input(
        "Choose table implementation:\n\t1)Binary Search Tree\n\t2)B-Tree\n\t3)Exit\n"
    )

    #BST option
    if (option == "1"):
        print("========= BINARY SEARCH TREE =========")

        #call to method and time
        start = time.time()
        tree = readIntoBST()
        end = time.time()

        #results
        print("Number of nodes: ", bst.countNodes(tree))
        print("Height: ", bst.Height(tree))
        print("Time elapsed building BST: " + "{:.2f}".format(end - start) +
              " seconds.")

        #display tree option
        if (input("Do you want to print the stored tree?\n\t1)Yes\n\t2)No\n")
                == "1"):
            printTree(tree)

        #similarities
        print("Reading word file to determine similarities...")
        start = time.time()
        similaritiesBST(tree)
        end = time.time()
        print("Running time for binary search tree query processing: " +
              "{:.2f}".format(end - start) + " seconds.")