title: Depth First Search Empty Set Error
body: <p>I'm making a program that determines whether or not a directed graph is strongly connected. The graph consists of 2 strings, 1 pointing to the other, and an optional numerical edge weight (defaults to True if no number).</p>
  
  <p>I have a defaultdict(dict):</p>
  
  <pre><code>import collections
  myDefaultDict = 
          {'A': {'B': True},
           'B': {'C': True},
           'C': {'D': True, 'E': True},
           'D': {'A': True},
           'E': {'C': True}})
  </code></pre>
  
  <p>I then have a set of the strings:</p>
  
  <pre><code>myNewSet = {'D', 'E', 'C', 'A', 'B'}
  </code></pre>
  
  <p>I then call my Depth First Search function:</p>
  
  <pre><code>for i in myNewSet:
      newSet = graph_DFT(i)
      print(newSet)
      break
  def graph_DFT(start):
      functionSet = set() # Contains all visited nodes
      myStack = []
      myStack.append(start)
      if not myStack:
          node = myStack.pop()
          for neighbor in myDefaultDict[node]:
              if neighbor not in functionSet:
                  functionSet.add(neighbor)
                  myStack.append(neighbor)
  
      return functionSet # Return the set with the visited nodes
  </code></pre>
  
  <p>The problem is the <code>print(newSet)</code>. This example graph, is strongly connected. That is you can reach every vertex from one vertex. However <code>print(newSet)</code> displays:</p>
  
  <pre><code>set() # But it should be equal to myNewSet, because this is a strongly connected graph
  </code></pre>
  
  <p>Why is my <code>newSet</code> empty? Shouldn't it be equal to <code>myNewSet</code>? I need it to, because this depends on how I handle the rest of my program, so I might be doing something wrong in my graph_DFT function.
  Thanks for any help!</p>