bst_1 = BST() bst_2 = BST() bst_3 = BST() DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ" DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ" for data in DATA1: letter = Letter(data) bst_1.insert(letter) for data in DATA2: letter = Letter(data) bst_2.insert(letter) for data in DATA3: letter = Letter(data) bst_3.insert(letter) fh = open('otoos610.txt', 'r') do_comparisons(fh, bst_1) do_comparisons(fh, bst_2) do_comparisons(fh, bst_3) total_1 = comparison_total(bst_1) total_2 = comparison_total(bst_2) total_3 = comparison_total(bst_3) print("DATA1 BST: {}".format(total_1)) print("DATA2 BST: {}".format(total_2)) print("DATA3 BST: {}".format(total_3))
for i in DATA2: bst2.insert(Letter(i[0])) for i in DATA3: bst3.insert(Letter(i[0])) f_variable = open("miserables.txt","r") print("Comparing by order: ABCDEFGHIJKLMNOPQRSTUVWXYZ") do_comparisons(f_variable, bst1) total = comparison_total(bst1) print("Total Comparisons: {:,.0f}".format(total)) print("------------------------------------------------------------") print("Comparing by order: MFTCJPWADHKNRUYBEIGLOQSVXZ") do_comparisons(f_variable, bst2) total = comparison_total(bst2) print("Total Comparisons: {:,.0f}".format(total)) print("------------------------------------------------------------")
from functions import do_comparisons, comparison_total, letter_table DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ" DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ" bst1 = BST() bst2 = BST() bst3 = BST() fill_letter_bst(bst1, DATA1) fill_letter_bst(bst2, DATA2) fill_letter_bst(bst3, DATA3) fn = "miserables.txt" fv = open(fn, "r", encoding="utf-8") do_comparisons(fv, bst1) t1 = comparison_total(bst1) fv = open(fn, "r", encoding="utf-8") do_comparisons(fv, bst2) t2 = comparison_total(bst2) fv = open(fn, "r", encoding="utf-8") do_comparisons(fv, bst3) t3 = comparison_total(bst3) print("Comparing by order: ABCDEFGHIJKLMNOPQRSTUVWXYZ") print("{}".format(t1)) print("------------------------------------------------------------") print("Comparing by order: MFTCJPWADHKNRUYBEIGLOQSVXZ") print("{}".format(t2)) print("------------------------------------------------------------") print("Comparing by order: ETAOINSHRDLUCMPFYWGBVKJXZQ") print("{}".format(t3)) print("------------------------------------------------------------")
""" ------------------------------------------------------------------------ Assignment 9, Task 2 - Hash_Set_sorted ------------------------------------------------------------------------ Author: Nicolas Mills ID: 180856100 Email: [email protected] __updated__ = 2019-03-25 ------------------------------------------------------------------------ """ from functions import insert_words, comparison_total from Hash_Set_sorted import Hash_Set print("Using array-based Sorted List Hash_Set") fv = open('miserables.txt', 'r') hs = Hash_Set(20) insert_words(fv, hs) total, max_word = comparison_total(hs) print("\nTotal Comparisons: {:,}".format(total)) print("Word with max comparisons: {}: {:,}".format(max_word.word, max_word.comparisons))
""" ------------------------------------------------------------------------ Assignment 8, Task 3 ------------------------------------------------------------------------ Author: Nicolas Mills ID: 180856100 Email: [email protected] __updated__ = 2019-03-22 ------------------------------------------------------------------------ """ from functions import do_comparisons, comparison_total, \ letter_table from Letter import Letter from BST_linked import BST from t02 import DATA3 bst_3 = BST() for data in DATA3: letter = Letter(data) bst_3.insert(letter) fh = open('otoos610.txt', 'r') do_comparisons(fh, bst_3) total_3 = comparison_total(bst_3) print("DATA3 BST: {}".format(total_3)) letter_table(bst_3)
""" ------------------------------------------------------- t03 ------------------------------------------------------- Author: Anshul Khatri ID: 193313680 Email: [email protected] Section: CP164 Winter 2020 __updated__ = "2020-04-03" ------------------------------------------------------- """ from functions import insert_words, comparison_total from Hash_Set_array import Hash_Set fv = open('miserables.txt', 'r') hash_1 = Hash_Set(20) insert_words(fv, hash_1) total, max_word = comparison_total(hash_1) print("Using BST Hash_Set") print("Total Comparisons: {} ".format(total)) print("Word with maximum comparisons '{}': {}".format(max_word.word, max_word.comparisons))
for i in DATA1: val = Letter(i) bst1.insert(val) for i in DATA2: val = Letter(i) bst2.insert(val) for i in DATA3: val = Letter(i) bst3.insert(val) test_file = open('otoos610.txt', 'r', encoding='utf-8') test_file = test_file.read() do_comparisons(test_file, bst1) total1 = comparison_total(bst1) do_comparisons(test_file, bst2) total2 = comparison_total(bst2) do_comparisons(test_file, bst3) total3 = comparison_total(bst3) print('Comparing by order: {}'.format(DATA1)) print('Total comparisons: {:,}'.format(total1)) print(SEP) print('Comparing by order: {}'.format(DATA2)) print('Total comparisons: {:,}'.format(total2)) print(SEP) print('Comparing by order: {}'.format(DATA3)) print('Total comparisons: {:,}'.format(total3))