Skip to content

Commit

Permalink
Fixed compilation errors, fixes for readability/convention, changed d…
Browse files Browse the repository at this point in the history
…ouble equals to boolean equality operator 'is'
  • Loading branch information
Alvin Nguyen authored and Alvin Nguyen committed Oct 10, 2017
1 parent 3ecb193 commit dc5e86b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions data_structures/Graph/Breadth_First_Search.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class GRAPH:
"""docstring for GRAPH"""
def __init__(self, nodes):
self.nodes=nodes
self.graph=[[0]*nodes for i in range (nodes)]
self.visited=[0]*nodes
self.nodes = nodes
self.graph = [[0]*nodes for i in range (nodes)]
self.visited = [0]*nodes


def show(self):
Expand All @@ -23,7 +23,7 @@ def bfs(self,v):
v = queue[0]
for u in range(self.vertex):
if self.graph[v][u] == 1:
if visited[u]== False:
if visited[u] is False:
visited[u] = True
queue.append(u)
print('%d visited' % (u +1))
Expand All @@ -41,30 +41,32 @@ def bfs(self,v):
g.add_edge(5,9)
g.add_edge(6,10)
g.bfs(4)
=======
print self.graph

print(self.graph)

def add_edge(self, i, j):
self.graph[i][j]=1
self.graph[j][i]=1

def bfs(self,s):
queue=[s]
self.visited[s]=1
while len(queue)!=0:
x=queue.pop(0)
def bfs(self, s):
queue = [s]
self.visited[s] = 1
while len(queue)!= 0:
x = queue.pop(0)
print(x)
for i in range(0,self.nodes):
if self.graph[x][i]==1 and self.visited[i]==0:
for i in range(0, self.nodes):
if self.graph[x][i] == 1 and self.visited[i] == 0:
queue.append(i)
self.visited[i]=1
self.visited[i] = 1

n=int(input("Enter the number of Nodes : "))
g=GRAPH(n)
e=int(input("Enter the no of edges : "))
n = int(input("Enter the number of Nodes : "))
g = GRAPH(n)
e = int(input("Enter the no of edges : "))
print("Enter the edges (u v)")
for i in range(0,e):
u,v=map(int, raw_input().split())
g.add_edge(u,v)
s=int(input("Enter the source node :"))

for i in range(0, e):
u ,v = map(int, raw_input().split())
g.add_edge(u, v)

s = int(input("Enter the source node :"))
g.bfs(s)

0 comments on commit dc5e86b

Please sign in to comment.