I have been vimified | Graph algo #2

Inspired from slides I decided to write my own DFS implementation [ Just to get the hang of vim ].

Nah! I actually wrote lots of code [ Now I force my self to make Django applications on vim , more on that later. ] to get the hang of it, Just passing DFS gist here because I think it is cool 😛 .

It was fun writing it because now I feel like a vim ninja. After weeks of frustration I finally feel like I have got the hang of it. I can perform all the basic thing like buffer copy paste , clipboard copy paste with indentations 🙂 ,beautiful color scheme , awesome iterative search , auto complete , python auto indent , gist , running scripts from vim and much more :

Here instead of making visited dictionary object I instead made visited list and conditioned if in list to avoid putting up the visited in stack .


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'])}
s= 'A'
visited = set()
stack = [s]
while stack:
vertex = stack.pop()
if vertex not in visited:
visited.add(vertex)
stack.extend(graph[vertex] – visited)
print visited

view raw

my_dfs.py

hosted with ❤ by GitHub

Leave a comment