Skip to content

Commit 1a5df6b

Browse files
author
Shivam Arora
committed
Added the method to find the isolated nodes in the graph
1 parent 5061722 commit 1a5df6b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

graphs/basic_graphs.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from __future__ import print_function
22

33
try:
4-
raw_input # Python 2
4+
raw_input # Python 2
55
except NameError:
66
raw_input = input # Python 3
77

88
try:
9-
xrange # Python 2
9+
xrange # Python 2
1010
except NameError:
11-
xrange = range # Python 3
11+
xrange = range # Python 3
1212

1313
# Accept No. of Nodes and edges
1414
n, m = map(int, raw_input().split(" "))
@@ -141,7 +141,7 @@ def dijk(G, s):
141141

142142
def topo(G, ind=None, Q=[1]):
143143
if ind is None:
144-
ind = [0] * (len(G) + 1) # SInce oth Index is ignored
144+
ind = [0] * (len(G) + 1) # SInce oth Index is ignored
145145
for u in G:
146146
for v in G[u]:
147147
ind[v] += 1
@@ -279,3 +279,12 @@ def krusk(E_and_n):
279279
s[j].update(s[i])
280280
s.pop(i)
281281
break
282+
283+
284+
# find the isolated node in the graph
285+
def find_isolated_nodes(graph):
286+
isolated = []
287+
for node in graph:
288+
if not graph[node]:
289+
isolated.append(node)
290+
return isolated

0 commit comments

Comments
 (0)