from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

import numpy as np


def bfs(graph_adj_d, v_start):
    """Breadth First Search (BFS) algorithm with single source 
    by iteration using queue.

    Note: There is no intuitive way to combine BFS & recursion,
    since BFS goes level by level.

    Time complexity for graph G(V, E): O(|V|+|E|).
    """
    distance_d = {v: np.inf for v in graph_adj_d.keys()}
    distance_d[v_start] = 0

    visit_queue = []
    visit_queue.insert(0, v_start)
    
    while visit_queue:
        v_visit = visit_queue.pop()
        for v_neighbor in graph_adj_d[v_visit]:
            # If v_neighbor is not visited.
            if np.isinf(distance_d[v_neighbor]):
                visit_queue.insert(0, v_neighbor)
                distance_d[v_neighbor] = distance_d[v_visit] + 1
    return distance_d


def main():
    # Undirected graph by adjacency list.
    graph_adj_d = {
        'A': ['B', 'D', 'G'],
        'B': ['A', 'E', 'F'],
        'C': ['F', 'H'],
        'D': ['A', 'F'],
        'E': ['B', 'G'],
        'F': ['B', 'C', 'D'],
        'G': ['A', 'E'],
        'H': ['C']
    }

    v_start = 'A'
    print('Start vertex: {}'.format(v_start))
    distance_d = bfs(graph_adj_d, v_start)
    print('Using BFS with queue, the distance dict is\n{}'
          .format(distance_d))


if __name__ == '__main__':
    main()

@@ -107,28 +107,8 @@
 on%0A%0A
-import numpy as np%0A%0A
 %0Adef
@@ -154,15 +154,15 @@
 dth 
-F
+f
 irst 
-S
+s
 earc
@@ -179,16 +179,38 @@
 gorithm 
+in graph G(V, E) %0A    
 with sin
@@ -220,21 +220,16 @@
  source 
-%0A    
 by itera
@@ -257,16 +257,23 @@
   Note: 
+%0A    - 
 There is
@@ -322,16 +322,18 @@
 on,%0A    
+  
 since BF
@@ -359,56 +359,154 @@
 el.%0A
-%0A
+ 
    
+-
  T
-ime complexity for graph G(V, E): O(%7CV%7C+%7CE
+his BFS algorithm can find Shortes Reach Problem%0A      in %22un-weighted%22 graph.%0A%0A    Time complexity: O(%7CV%7C+%7CE%7C).%0A    Space complexity: O(%7CV
 %7C).%0A
@@ -538,14 +538,20 @@
 %7Bv: 
-np.
+float('
 inf
+')
  for
@@ -836,17 +836,8 @@
  if 
-np.isinf(
 dist
@@ -854,16 +854,31 @@
 eighbor%5D
+ == float('inf'
 ):%0A     
@@ -1423,14 +1423,8 @@
 nt('
-Using 
 BFS 
@@ -1432,19 +1432,8 @@
 ith 
-queue, the 
 dist
@@ -1441,19 +1441,17 @@
 nce dict
- is
+:
 %5Cn%7B%7D'%0A  

Revise docstring for shortest reach & float('inf')