Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 8th, 2009, 9:17 PM   #1
Skimanner
Newbie
 
Join Date: Oct 2009
Posts: 13
Rep Power: 0 Skimanner is on a distinguished road
BFS Algorithm

This is a long problem but it has me totally lost so I'm gonna type it out and hope for the best. I'm studying for a mid-term so I don't want the exact answer to it, I just wanna understand what the algorithm is supposed to do. The only thing I'm really sure of is that it should be a breath-first search since the runtime needs to be O(m+n). Thanks in advance for any help.

Some of your friends have become amateur lepidopterists (they study butterflies). Often when they return from a trip with specimens of butterflies, it is very difficult for them to tell how many distinct species they've caught, thanks to the fact that many species look very similar to one another.

One day they return with n butterflies, and they believe that each belongs to one of two different species, which we'll call A and B for purposes of this discussion. They'd like to divide the n specimens into two groups, that that belong to A and those that belong to B but it's very hard for them to directly label any one specimen. So they decide to adopt the following approach.

For each pair of specimens i and j, they study them carefully side by side. If they're confident enouch in their judgment, then they label the pair (i,j) either "same" (meaning they believe them both to come from the same species) or "different" (meaning they believe them to com from different species). They also have the option of rendering no judgment on a given pair, in which case we'll call the pair ambiguous.

So now they have the collection of n specimens, as well as a collection of m judgments (either "same" or "different") for the pairs that were not declared to be ambiguous. They'd like to know if this data is consistent with the idea that each butterfly is from one of species A or B. So more concretely, we'll declare the m judgments to be consistent if it is possible to label each specimen either A or B in such a way that for each pair (i,j) labeled "same," it is the case that ia and j have the same label; and for each pair (i,j) labeled "different," it is the case that i and j have different labels. They're in the middle of tediously working out whether their judgments are consistent, when one of them realizes that you probably have an algorithm that would answer this question right away.

Give an algorithm with running time O(m+n) that determines whether the m judgments are consistent.
Skimanner is offline   Reply With Quote
Old Oct 8th, 2009, 10:03 PM   #2
Sane
Programming Guru

 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, ON
Posts: 3,485
Rep Power: 10 Sane will become famous soon enoughSane will become famous soon enough
Send a message via MSN to Sane
Re: BFS Algorithm

The algorithm involves traversing a graph. Whether you do this with a DFS or a BFS is up to you, but I would strongly suggest a DFS. A BFS is typically reserved for the special cases where you need to process nodes in order of distance from the source.

Create some sample data, take out a sheet of paper, and then draw a graph where a vertex represents a butterfly (n of these) and an edge represents a label (m of these). Draw a green-coloured edge between butterflies that are the same. Draw a red-coloured edge between butterflies that are different. Draw no edge between ambiguities.

Look at the graph, and see if you can solve it by hand. How were you able to tell if it's consistent or not? If you don't know how you did it, then try again on some more data until you see the pattern. Can you generalize your observations? Turn these observations into concrete statements (or constraints) that must be satisfied for it to be consistent.

Then you can do a series of graph traversals to gather the information necessary to evaluate and test the requirements for consistency.
__________________
|¯_/ . /¯\ . |¯\|¯| |_¯ PFO's Folding@Home Team
/¯_| /_/\_\ |_|\_| |__ Sane's Monthly Algorithms Challenges
Sane is offline   Reply With Quote
Old Oct 8th, 2009, 10:57 PM   #3
Skimanner
Newbie
 
Join Date: Oct 2009
Posts: 13
Rep Power: 0 Skimanner is on a distinguished road
Re: BFS Algorithm

So what were looking at here is that we are gonna have a given graph with colored edges based on there judgements and as we go through the DFS we compare the color of the edge the graph has to see if its consistent with the color it should be?
Skimanner is offline   Reply With Quote
Old Oct 9th, 2009, 12:15 AM   #4
Sane
Programming Guru

 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, ON
Posts: 3,485
Rep Power: 10 Sane will become famous soon enoughSane will become famous soon enough
Send a message via MSN to Sane
Re: BFS Algorithm

It's not "as we go through the DFS we compare the colors". Thoroughly reread my last post. In particular, the part about "turning your observations into concrete statements (or constraints) that must be satisfied". Then as you traverse the graph, you can gather data about the graph. Afterwards, you use this data and compare it with what you expect. The important part is you need to be able to solve this problem, by hand, to figure out what this data is.
__________________
|¯_/ . /¯\ . |¯\|¯| |_¯ PFO's Folding@Home Team
/¯_| /_/\_\ |_|\_| |__ Sane's Monthly Algorithms Challenges
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SMAC #10 [09-09] - Really Secure Algorithm (Senior) Sane Software Design and Algorithms 2 Oct 5th, 2009 10:41 PM
Feedback On Algorithm With C++ Sane C++ 3 Apr 17th, 2008 5:08 PM
data tree for A* algorithm cwl157 Java 0 Sep 17th, 2007 3:48 PM
algorithm of fast exponentiation MicRo C++ 1 Mar 12th, 2006 5:29 PM
SpcFileWipe algorithm in Secure Programming Cookbook not working c0ldshadow C++ 1 Aug 7th, 2005 7:40 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:32 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC