def bst_sort(a):
        """
        -------------------------------------------------------
        Sorts an array using the Tree Sort algorithm.
        Use: Sorts.bst_sort(a)
        -------------------------------------------------------
        Parameters:
            a - an array of comparable elements (?)
        Returns:
            None
        -------------------------------------------------------
        """
        bst = BST()

        for v in a:
            bst.insert(v)

        a[:] = bst.inorder()
        return
Exemple #2
0
"""
------------------------------------------------------------------------
BST Implementations
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-03-20
------------------------------------------------------------------------
"""
from BST_linked import BST

print("Testing BST#is_balanced")

print("\n\nEmpty tree")
bst = BST()
print("Contents: {}".format([val for val in bst]))
balanced = bst.is_balanced()
print("Balanced? {}".format(balanced))
print("Expected: {}".format(True))

print("\n\nNon-empty tree not balanced")
bst = BST()
for val in [11,22,9,33,44,25]:
    bst.insert(val)
print("Contents: {}".format([val for val in bst]))
balanced = bst.is_balanced()
print("Balanced? {}".format(balanced))
print("Expected: {}".format(False))

print("\n\nNon-empty tree balanced")
Exemple #3
0
"""
-------------------------------------------------------
[program description]
-------------------------------------------------------
Author:  Max Dann
ID:      190274440
Email:   [email protected]
__updated__ = "2020-03-24"
-------------------------------------------------------
"""

from BST_linked import BST
from Letter import fill_letter_bst
from functions import do_comparisons, comparison_total, letter_table

DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

bst2 = BST()

fill_letter_bst(bst2, DATA2)

letter_table(bst2)
Exemple #4
0
ID:      193313680
Email:   [email protected]
Section: CP164 Winter 2020
__updated__ = "2020-03-25"
-------------------------------------------------------
"""
from BST_linked import BST
from functions import comparison_total , do_comparisons
from Letter import Letter


DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

bst1 = BST()
bst2 = BST()
bst3 = BST()

for i in DATA1:
    bst1.insert(Letter(i[0]))


for i in DATA2:
    bst2.insert(Letter(i[0]))
    

for i in DATA3:
    bst3.insert(Letter(i[0]))
    
f_variable = open("miserables.txt","r")
Exemple #5
0
"""
------------------------------------------------------------------------
Assignment 8, Task 2 - Letter comparisons
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-03-21
------------------------------------------------------------------------
"""
from functions import comparison_total, do_comparisons, \
letter_table
from BST_linked import BST
from Letter import Letter

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)
Exemple #6
0
"""
------------------------------------------------------------------------
Lab 8, Task 5 - encode_morse
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-03-11
------------------------------------------------------------------------
"""
from BST_linked import BST
from morse import encode_morse, fill_letter_bst, data1

letter_bst = BST()
values = data1

fill_letter_bst(letter_bst, values)

text = "Hello, my name is Nick Mills."

morse = encode_morse(letter_bst, text)

print("Text: {}".format(text))
print("Morse: {}".format(morse))
Exemple #7
0
"""
------------------------------------------------------------------------
Lab 8, Task 6 - decode_morse
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-03-11
------------------------------------------------------------------------
"""
from BST_linked import BST
from morse import decode_morse, fill_code_bst, data1

code_bst = BST()
values = data1

fill_code_bst(code_bst, values)

morse = """.... . .-.. .-.. --- 
-- -.-- 
-. .- -- . 
.. ... 
-. .. -.-. -.- 
-- .. .-.. .-.. ..."""

print("\nTest with BST as None")
text = decode_morse(None, morse)
print("Morse: {}".format(morse))
print("Text: {}".format(text))

print("\nTest with code as None")
Exemple #8
0
    """
    -------------------------------------------------------
    description
    Use:
    -------------------------------------------------------
    Parameters:
        name - description (type)
    Returns:
         name - description (type)
    ------------------------------------------------------

    """


start = time.time()
bst1 = BST()
bst2 = BST()
bst3 = BST()

DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

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)
Exemple #9
0
"""
-------------------------------------------------------
[program 1]
-------------------------------------------------------
Author:  Anshul Khatri
ID:      193313680
Email:   [email protected]
Section: CP164 Winter 2020
__updated__ = "2020-03-25"
-------------------------------------------------------
"""

from BST_linked import BST

bst1 = BST()
bst2 = BST()

bst1.insert(3)
bst1.insert(4)
bst1.insert(1)
bst1.insert(5)
bst1.insert(9)
bst1.insert(2)

bst2.insert(6)
bst2.insert(4)
bst2.insert(7)
bst2.insert(2)
bst2.insert(3)
bst2.insert(1)
Exemple #10
0
"""
-------------------------------------------------------
[program description]
-------------------------------------------------------
Author:  Max Dann
ID:      190274440
Email:   [email protected]
__updated__ = "2020-03-09"
-------------------------------------------------------
"""
from BST_linked import BST
from morse import decode_morse, fill_code_bst, ByLetter
bst = BST()
text = "... --- ..."
values = (('A', '.-'), ('B', '-...'), ('C', '-.-.'), ('D', '-..'), ('E', '.'),
          ('F', '..-.'), ('G', '--.'), ('H', '....'), ('I', '..'),
          ('J', '.---'), ('K', '-.-'), ('L', '.-..'), ('M', '--'), ('N', '-.'),
          ('O', '---'), ('P', '.--.'), ('Q', '--.-'), ('R', '.-.'),
          ('S', '...'), ('T', '-'), ('U', '..--'), ('V', '...-'), ('W', '.--'),
          ('X', '-..-'), ('Y', '-.--'), ('Z', '--..'))
fill_code_bst(bst, values)

text = decode_morse(bst, text)
print(text)
Exemple #11
0
"""
------------------------------------------------------------------------
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)
Exemple #12
0
"""
------------------------------------------------------------------------
Assignment 9, Task 4 - node_counts, __contains__, parent (iterative), parent_r (recursive)
------------------------------------------------------------------------
Author: Nicolas Mills
ID:     180856100
Email:  [email protected]
__updated__ = 2019-03-28
------------------------------------------------------------------------
"""
from BST_linked import BST

print('Testing BST#node_counts')

print('\n\nEmpty BST')
bst = BST()

zero, one, two = bst.node_counts()
print("Nodes w/ ZERO children: {}\tExpected: {}".format(zero, 0))
print("Nodes w/ ONE children: {}\t\tExpected: {}".format(one, 0))
print("Nodes w/ TWO children: {}\t\tExpected: {}".format(two, 0))

print('\n\nNon-empty BST with only two nodes')
bst = BST()
for val in [2,4]:
    bst.insert(val)
zero, one, two = bst.node_counts()
print("Nodes w/ ZERO children: {}\tExpected: {}".format(zero, 1))
print("Nodes w/ ONE child: {}\t\tExpected: {}".format(one, 1))
print("Nodes w/ TWO children: {}\t\tExpected: {}".format(two, 0))
Exemple #13
0
"""
-------------------------------------------------------
[program 3]
-------------------------------------------------------
Author:  Anshul Khatri
ID:      193313680
Email:   [email protected]
Section: CP164 Winter 2020
__updated__ = "2020-03-27"
-------------------------------------------------------
"""

from functions import letter_table, do_comparisons
from Letter import Letter
from BST_linked import BST

DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

fv = open("miserables.txt","r")
bst1 = BST()
for letter in DATA3:
    ob = Letter(letter)
    bst1.insert(ob)
    
do_comparisons(fv, bst1)

letter_table(bst1)
Exemple #14
0
"""
-------------------------------------------------------
[program description]
-------------------------------------------------------
Author:  Max Dann
ID:      190274440
Email:   [email protected]
__updated__ = "2020-03-31"
-------------------------------------------------------
"""
from BST_linked import BST
bst = BST()
bst.insert(11)
bst.insert(7)
bst.insert(15)
bst.insert(6)
bst.insert(9)
bst.insert(12)
bst.insert(18)
bst.insert(8)
yes = 7
no = 67
print(bst.node_counts())
print(yes in bst)
print(no in bst)
print(bst.parent(yes))
print(bst.parent_r(yes))
Exemple #15
0
def new_slot():
    new_slot = BST()
    return new_slot
Exemple #16
0
"""
-------------------------------------------------------
[program description]
-------------------------------------------------------
Author:  Anshul Khatri
ID:      193313680
Email:   [email protected]
Section: CP164 Winter 2020
__updated__ = "2020-04-03"
-------------------------------------------------------
"""
from BST_linked import BST

bst = BST()

num = [4, 2, 9, 3, 6]

for i in num:
    bst.insert(i)

print(bst.node_counts())
print(bst.__contains__(2))
print(bst.parent(2))
print(bst.parent_r(2))
Exemple #17
0
[program description]
-------------------------------------------------------
Author:  Max Dann
ID:      190274440
Email:   [email protected]
__updated__ = "2020-03-24"
-------------------------------------------------------
"""
from BST_linked import BST
from Letter import fill_letter_bst
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)
Exemple #18
0
"""
-------------------------------------------------------
[program description]
-------------------------------------------------------
Author:  Max Dann
ID:      190274440
Email:   [email protected]
__updated__ = "2020-03-23"
-------------------------------------------------------
"""
from BST_linked import BST

tree = BST()
tree.insert(5)
tree.insert(6)
tree.insert(3)
tree.insert(1)
tree.insert(4)
tree.insert(8)


'''
print(tree.is_valid())
tree._root._right._value = 4
print(tree.is_valid())
'''
'''
tree2 = BST()
for i in range(1,7):
    tree2.insert(i)
'''