From: equinox Date: 2008-11-21T01:46:18+09:00 Subject: Re: BFS in ruby from a hash On Nov 20, 8:52 am, Todd Benson wrote: > On Thu, Nov 20, 2008 at 8:27 AM, Robert Klemme > > > > wrote: > > 2008/11/20 Hugh Sasse : > > >> On Thu, 20 Nov 2008, equinox wrote: > > >>> Yes I know the algorithm of doing BFS, however I can't see where a > >>> hash is a graph structure... > > > Well, isn't this (i.e. analyzing the problem) part of your assignment? > > This really looks like a homework assignment... > > >>> 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, not necessarily. You just need to look at the Hash as a vertex > > collection.  I'm not going to say more... :-) > > > Kind regards > > > robert > > Definitely agree with robert here.  But the $database seems contrived. > > I would guess the powers that be want you to come up with a clever way > to check your nodes.  To be honest my first solution (that I thought > was clever) turned out to walk each node from left to right, but just > wasn't even close to bfs.  Your parent node, with this type of hash, > is probably supposed to be the first one, and then stack them from > there. > > Todd so I'll need a queue to do this? How do you create a queue in ruby?