Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

scheme - Depth-first search (DFS) for undirected graphs

I was looking at this.

If I were just given a list that contained the number of edges (graph), pair of edges, a origin and a destination, how would I figure out if there is or isn't a path?

I have some idea, but just need a bit of help in terms of starting in scheme.

(is_it_a_path? '(4 ((1 2) (2 3) (3 4) (2 4))) 1 4) ; returns true 

(is_it_a_path? '(3 ((1 2) (2 3) (3 1))) 2 3)       ; also returns true 

In the following 4 is the number of vertices, (1 2)... and so are are the edges and 1 is the start and 4 is the end. Basically from these you are looking at whether there is a path from 1 to 4 in the following defined graph. I hope that can clarify what I mean.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Did you see John Clements's earlier response to look at How to Design Programs? It has a Chapter on how to design programs that deal with graphs.

As a meta-answer: the question you're asking, about how to get started on a problem that you're unfamiliar with, is the heart of the HtDP book. Have you looked at it? It's essentially an adaptation of Polya's How To Solve It, but tailored for writing computer programs rather than math proofs. The Second edition draft may be easier to read.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...