Skip to content

Instantly share code, notes, and snippets.

View ChetanKhanna's full-sized avatar
:electron:
Hello World

Chetan Khanna ChetanKhanna

:electron:
Hello World
View GitHub Profile
@ChetanKhanna
ChetanKhanna / priority_q.py
Created September 18, 2018 20:04
Priority Queue implementation
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
@ChetanKhanna
ChetanKhanna / BST.py
Created September 18, 2018 20:02
Binary Search Tree implementation
"""
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
@ChetanKhanna
ChetanKhanna / tree.py
Created September 18, 2018 20:01
Generic Tree implementation in python
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)
@ChetanKhanna
ChetanKhanna / bin_tree.py
Created September 18, 2018 19:59
Binary Tree Implementation
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: