Trees
Rustom Mody
rustompmody at gmail.com
Tue Jan 20 21:03:23 EST 2015
On Wednesday, January 21, 2015 at 7:19:39 AM UTC+5:30, Paul Rubin wrote:
> Rustom Mody writes:
> > ## The depth first algorithm
> > dfs (L x) = [x]
> > dfs (B x lst rst) = [x] ++ dfs lst ++ dfs rst
>
> Cute. I can't resist posting the similar breadth first algorithm:
>
> bfs (L x) = [x]
> bfs (B x lst rst) = bfs lst ++ [x] ++ bfs rst
>
> > *Main> dfs t
> > [6,2,1,4,3,5,8,7,9]
>
> *Main> bfs t
> [1,2,3,4,5,6,7,8,9]
Eh??
Thats not bfs. That's inorder traversal
The bfs of http://www-math.ucdenver.edu/~wcherowi/courses/m4408/gtln8.html
is
[6, 2,8, 1,4,7,9, 3,5]
More information about the Python-list
mailing list