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
#From shell | |
virtualenv flaskenv -p python3 | |
ls flaskenv | |
ls flaskenv/bin/ | |
#Activate virtual environment | |
. flaskenv/bin/activate | |
pip install Flask | |
pip install flask-wtf | |
pip install email_validator |
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
def topological_sort(graph): | |
queue = Queue() | |
indegree_map = {} | |
for i in range(graph.num_vertices): | |
indegree_map[i] = graph.get_indegree(i) | |
#Add root node to the queue | |
if indegree_map[i] == 0: |
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
def breadth_first(graph, start=0): | |
queue = Queue() | |
queue.put(start) | |
#Return an array of shape (graph.num_vertices, ), boolean values initialised as false | |
visited = np.full((graph.num_vertices, ), False, dtype = bool) | |
while not queue.empty(): | |
vertex = queue.get() |
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
def depth_first(graph,visited,current = 0): | |
if visited[current] : | |
return | |
visited[current] = True | |
print("Visited: ",current) | |
for vertex in graph.get_adjacent_vertices(current): |
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 abc | |
import numpy as np | |
class Graph(abc.ABC): | |
def __init__(self, num_vertices, directed = False): | |
self.num_vertices = num_vertices | |
self.directed = directed | |
@abc.abstractmethod |
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
#Pre-Order Depth First Search | |
def pre_order(node): | |
path = [] | |
if node: | |
path.append(node.data) | |
path = path + pre_order(node.get_left_child()) | |
path = path + pre_order(node.get_right_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
#Breadth First Search | |
class MyQueue: | |
def __init__(self): | |
"""Creat a new queue""" | |
self.items = [] | |
def is_empty(self): |
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 Node: | |
def __init__(self, data): | |
self.left = None | |
self.right = None | |
self.data = data | |
def get_left_child(self): | |
return self.left |