graph = {'A': set(['B','C']),
        'B': set(['A','D','E']),
        'C': set(['A','F']),
        'D': set(['B']),
        'E': set(['B','F']),
        'F': set(['C','E'])}

def bfs(graph,start):

    visited = set()
    queue = [start]

    while queue:
        vertex = queue.pop(0)
        if vertex not in visited:
            visited.add(vertex)
            queue.extend(graph[vertex]-visited)
    return visited

def dfs(graph,start):

    visited = set()
    stack = [start]

    while stack:
        vertex = stack.pop(0)
        if vertex not in visited:
            visited.add(vertex)
            stack.extend(graph[vertex]-visited)
    return visited

print(dfs(graph,'C'))
print(bfs(graph,'C'))
