Skip to content

Instantly share code, notes, and snippets.

View sori424's full-sized avatar
๐Ÿ‹๏ธโ€โ™‚๏ธ
Focusing

Soyoung Oh sori424

๐Ÿ‹๏ธโ€โ™‚๏ธ
Focusing
View GitHub Profile
@sori424
sori424 / Kruskal.py
Created December 13, 2019 09:16
kruskal MST using union and find ( implemented through python )
# get code from >> https://debuglog.tistory.com/84
parent = {}
rank = {}
def make_set(v):
parent[v] = v
rank[v] = 0
def find(v):
@sori424
sori424 / Prim.py
Created December 13, 2019 09:09
prim MST algo implemented by python
class Graph():
def __init__(self, size):
self.size = size
def printMST(self, parent):
for i in range(self.size):
print(parent[i],'-',i,'\t',self.graph[i][parent[i]])
def minKey(self, key, mstSet):
@sori424
sori424 / Floyd.py
Created December 13, 2019 09:01
floyd algorithm implemented through python
from typing import List
from copy import deepcopy
class Graph:
def __init__(self, size):
self.size = size
self.adj_matrix = [[float('inf')] * size for i in range(size)]
def add_edge(self, i, j, weight):
@sori424
sori424 / Dijkstra.py
Created December 13, 2019 08:52
dijkstra implemented through python
def dijkstra(start, size, weight):
# one vertex's adjacent vertecies list : distance
distance = weight[start]
# if visit the vertex, check it as True
visited = [False]*size
@sori424
sori424 / Knapsack.py
Last active December 13, 2019 08:53
greedy algorithm for knapsack problem(0/1 & fractional) implemented through python
val = [60, 120, 100]
wt = [10, 30, 20]
W = 50
def binary_knapSack(W, wt, val):
n = len(val)
k = [[0 for _ in range(W+1)] for _ in range(n+1)]
for i in range(n+1):
for w in range(W+1):