Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,628 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,052 people online right now. Registration is fast and FREE... Join Now!




help a tiny Scheme problem

 
Reply to this topicStart new topic

help a tiny Scheme problem

kidworld
post 4 Nov, 2005 - 07:22 PM
Post #1


New D.I.C Head

*
Joined: 4 Nov, 2005
Posts: 4


My Contributions


This is first time I played with Scheme, I got a question to design a scheme code to find a given undirected graph is connected. like ((a cool.gif (c d) (b d) (a c)) is connected but ((a cool.gif (c d) (b d) (a e)) is not connected. I try to thinking the soluion like what I did in C++, but failed . so I have no idea how to do this.
User is offlineProfile CardPM

Go to the top of the page

cyberscribe
post 5 Nov, 2005 - 10:51 AM
Post #2


humble.genius

Group Icon
Joined: 5 May, 2002
Posts: 1,062



Thanked 2 times

Dream Kudos: 154
My Contributions


QUOTE(kidworld @ Nov 4 2005, 09:19 PM)
CODE

((a b) (c d) (b d) (a c))

is connected but
CODE

((a b) (c d) (b d) (a e))

is not connected
  • This is a list; not an array.
  • This is recursion; not iteration.
  • This is Scheme; not C++

    Here's how I'd approach it: in recursion you can't "store" values, but you can pass them along so they persist. So, I'd start out with a function that takes two arguments: your original list, and a blank list. The second argument will be the stuff from the original list that is unmatched. Then you recurse through each pair, trying to match stuff in the pair against stuff left to be matched (i.e. first element to last element and last element to first element). When the first argument is empty, you check the second argument. If it's also emtpy, everything has been matched for continuity. Otherwise, if your matching algorithm is tight and there's stuff left to be matched, the graph is not continuous. Make sense?
Good luck! This one's tricky. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 03:44AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month