Skip to content

Instantly share code, notes, and snippets.

View raymondchua's full-sized avatar

Raymond Chua raymondchua

  • Montreal, Canada
View GitHub Profile
@raymondchua
raymondchua / bfs
Last active December 29, 2015 23:19
Breadth-First Search
#Breadth-first search, Python
from collections import deque
from graph import constructGraph
def bfsearch(root, vertex):
queue = deque([root])
visitedNodes = set()
#keep looking while queue is not empty
@raymondchua
raymondchua / graph
Created December 2, 2013 00:03
define a function to construct a graph
from node import Node
def constructGraph(vertex, edges):
vertices = dict([(vertex[i],Node(vertex[i])) for i in range(len(vertex))])
for i in vertices:
vertices[i].value = i
for (u,v) in edges:
@raymondchua
raymondchua / node
Created December 2, 2013 00:05
Creates an object node.
class Node:
def __init__(self,value):
self.value = value
self.adjacentNodes=[]
@raymondchua
raymondchua / PriorityQueue
Last active December 31, 2015 06:39
In priority queue, the elements are ordered according to the key values. The element with the lowest key value may be the head of the queue or it may be the last element in the queue depending on the programming language.
/*Priority Queue
In priority queue, the elements are ordered according to the key values.
The element with the lowest key value may be the head of the queue
or it may be the last element in the queue depending on the programming language.
poll() removes the element with the largest priority value
*/
import java.util.Comparator;
@raymondchua
raymondchua / DijkstraAlgo
Last active December 15, 2019 09:50
Java's implementation of Dijkstra's Algorithm
import java.util.PriorityQueue;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class DijkstraAlgo{
/* Dijkstra Algorithm
*
@raymondchua
raymondchua / AstarSearchAlgo
Last active June 28, 2024 02:00
A Star Search Algorithm, Java Implementation
import java.util.PriorityQueue;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
public class AstarSearchAlgo{