<filename>src/main/python/data_structure_practice/graph_examply.py
import collections
class graph:

    def __init__(self,gdict=None):
        if gdict is None:
            gdict = {}
        self.gdict = gdict
# Check for the visisted and unvisited nodes

def dfs(graph, start, visited = None):
    if visited is None:
        visited = set()
    visited.add(start)
    for next in graph[start] - visited:
        dfs(graph, next, visited)
    return visited

def bfs(graph, startnode):
# Track the visited and unvisited nodes using queue
        seen, queue = set([startnode]), collections.deque([startnode])
        while queue:
            vertex = queue.popleft()
            for node in graph[vertex]:
                if node not in seen:
                    seen.add(node)
                    queue.append(node)
        return queue



gdict = { "a" : set(["b","c"]),
                "b" : set(["a", "d"]),
                "c" : set(["a", "d"]),
                "d" : set(["e"]),
                "e" : set(["a"])
                }


print dfs(gdict, 'a')
print bfs(gdict, "a")

<filename>src/main/python/data_structure_practice/graph_examply.py
import collections
class graph:

    def __init__(self,gdict=None):
        if gdict is None:
            gdict = {}
        self.gdict = gdict
# Check for the visisted and unvisited nodes

def dfs(graph, start, visited = None):
    if visited is None:
        visited = set()
    visited.add(start)
    for next in graph[start] - visited:
        dfs(graph, next, visited)
    return visited

def bfs(graph, startnode):
# Track the visited and unvisited nodes using queue
        seen, queue = set([startnode]), collections.deque([startnode])
        while queue:
            vertex = queue.popleft()
            for node in graph[vertex]:
                if node not in seen:
                    seen.add(node)
                    queue.append(node)
        return queue



gdict = { "a" : set(["b","c"]),
                "b" : set(["a", "d"]),
                "c" : set(["a", "d"]),
                "d" : set(["e"]),
                "e" : set(["a"])
                }


print dfs(gdict, 'a')
print bfs(gdict, "a")

# Check for the visisted and unvisited nodes # Track the visited and unvisited nodes using queue