This file contains 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 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{ |
This file contains 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 java.util.PriorityQueue; | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
public class DijkstraAlgo{ | |
/* Dijkstra Algorithm | |
* |
This file contains 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
/*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; |
This file contains 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,value): | |
self.value = value | |
self.adjacentNodes=[] |
This file contains 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 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: |
This file contains 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, 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 |