From: Hugh Sasse Date: 2008-11-20T23:19:22+09:00 Subject: Re: BFS in ruby from a hash ---476953799-1184005324-1227190989=:13498 Content-Type: MULTIPART/MIXED; BOUNDARY="-476953799-1184005324-1227190989=:13498" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---476953799-1184005324-1227190989=:13498 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT On Thu, 20 Nov 2008, equinox wrote: > On Nov 20, 12:34�am, Robert Klemme wrote: > > On 20.11.2008 04:54, equinox wrote: > > > > > I want to do a breadth first search on a hash like below: > > > > >http://pastie.org/319366 > > > > > can anyone give me some idea where to start as I've never done bfs > > > (breadth first search) on hash before. > > > > http://en.wikipedia.org/wiki/Breadth-first_search#Algorithm_.28inform... > > > > If you just want to visit all nodes (i.e. not a search) then you need to > > remember all visited nodes and not put new nodes into the queue which > > you have seen already. > > > > Kind regards > > > > � � � � robert > > Yes I know the algorithm of doing BFS, however I can't see where a > hash is a graph structure... > How do I visit the child here? Which ones are trees in the same level? In the Pastie the keys point at arrays of strings. But in that example all the strings correspond to keys, except for lonelygirl13 which looks like a typo for the key lonelygirls13. Normally to make a tree with hashes you'd use hashes of hashes [of hashes [...]]. It seems to me you can't do Breadth first until you've got some Depth to not do first! Hugh > > ---476953799-1184005324-1227190989=:13498-- ---476953799-1184005324-1227190989=:13498--