This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
from pythonds.trees.binheap import BinHeap | |
from queue import PriorityQueue | |
""" What is a Prioruty Queue and Why to use it: | |
http://btechsmartclass.com/DS/U3_T6.html | |
""" | |
""" Inspirations: | |
https://dbader.org/blog/priority-queues-in-python | |
http://interactivepython.org/courselib/static/pythonds/Trees/BinaryHeapOperations.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Defining Binary Search Tree Data Structure | |
""" | |
class Node: | |
def __init__(self, val, right = None, left = None, parent = None ): | |
## Inspiration: | |
## http://interactivepython.org/runestone/static/pythonds/Trees/SearchTreeImplementation.html | |
self.val = val | |
self.left = left |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tree(): | |
def __init__(self, root, children = None): | |
self.root = root | |
if children: | |
self.children = [child for child in children] | |
else: | |
self.children = [] | |
def AddChild(self, child): | |
self.children.append(child) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinaryTree(): | |
def __init__(self, root, left = None, right = None): | |
self.root = root | |
self.left = left | |
self.right = right | |
def AddLeft(self, val): | |
if self.left == None: | |
self.left = val | |
else: |