开发者

How do I check if an undirected graph has a cycle using Scheme?

开发者 https://www.devze.com 2022-12-26 23:23 出处:网络
I have to determine if an undirected graph contains a cycle or not. I shoudn\'t use set! instructions.

I have to determine if an undirected graph contains a cycle or not. I shoudn't use set! instructions. I tried us开发者_开发知识库ing DFS, but I don't know how to mark the visited nodes.


Instead of marking nodes as visited, build a list that tracks which nodes have been visited. You'll have to pass the list along to recursive calls to DFS and add to it as you go.

0

精彩评论

暂无评论...
验证码 换一张
取 消