Thursday, April 15, 2010

Graphs - DFS, BFS in Python

Lately I've been playing with Python and I was curious to implement some graph algorithms. For a start I wrote the DFS and the BFS ones.

The output:
>>> import graphs
>>> graphs.bfs(2)
1 3 4 5 6 12 7 11 10
>>> graphs.dfs(2)
2 5 7 10 12 11 6 4 3 1

The test graph is:



With the following short script the graph will be drawn as png (thanks to the great pygraphviz tutorial):



So that it looks like this:


The BFS algorithm is as follows:



And the DFS one (exactly the same, just using a stack instead of a queue):

25 comments:

Anonymous said...

order tramadol online tramadol 50 mg vs tylenol #3 - buy tramadol online cod

Anonymous said...

generic xanax xanax 2mg white bars - xanax online no prescription mastercard

Anonymous said...

xanax 2mg generic brand for xanax - cheap generic xanax online

Anonymous said...

buy tramadol online tramadol 50 mg opiate - many 50mg tramadol overdose

Anonymous said...

carisoprodol 350 mg carisoprodol 350 mg generic - soma carisoprodol tablets used

Anonymous said...

buy tramadol online buy tramadol ampules - tramadol buy usa

Anonymous said...

carisoprodol 350 mg soma carisoprodol uses - carisoprodol 350 mg muscle relaxer

Anonymous said...

buy tramadol online can i order tramadol online legally - tramadol withdrawal wellbutrin

Anonymous said...

buy tramadol online tramadol for dogs sleepy - tramadol hcl time release

Anonymous said...

buy cialis online cialis daily use does work - cialis kopen

Anonymous said...

tramadol 50 mg online purchase of tramadol - tramadol zolpidem interaction

Anonymous said...

xanax online xanax buy online no prescription uk - xanax xr alcohol

Anonymous said...

buy tramadol no prescription canadian tramadol no prescription - is tramadol generic for ultram

Anonymous said...

buy cialis generic 20 mg cialis daily use - cialis 0 50

Anonymous said...

buy xanax online the xanax high - high on xanax feeling

Anonymous said...

buy cialis online buy cialis usa no prescription - cialis 5mg review

Anonymous said...

xanax online xanax show up on drug test - do xanax show up drug test

Anonymous said...

buy cialis online best online pharmacy cialis - cialis 2.5mg price

Anonymous said...

buy cialis no prescription cialis 5mg. price in usa - cialis jelly reviews

Anonymous said...

buy tramadol online many tramadol 50mg get high - tramadol online purchase

Anonymous said...

learn how to buy tramdadol buy tramadol in usa - where to buy tramadol usa

Anonymous said...

http://buytramadolonlinecool.com/#51726 tramadol hcl 50 mg muscle relaxer - safe order tramadol online

Anonymous said...

buy generic tramadol online buy cheap tramadol online cod - tramadol youtube

Anonymous said...

buy tramadol saturday delivery tramadol dosage severe pain - buy tramadol no prescription cheap

Anonymous said...

cheap tramadol buy tramadol no prescription cheap - tramadol no prescription mastercard

Categories

code (15) fun (2) linux (31) miscellaneous (9) music (8)

About me

I'm Adrian and this is my blog. Here I usually write about technical stuff (mostly about Linux).
Copyright: BY-NC_SA, Author: aeter