Krista Ryan
Krista Ryan

Reputation: 1

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

I have to determine if an undirected graph contains a cycle or not. I shoudn't use set! instructions. I tried using DFS, but I don't know how to mark the visited nodes.

Upvotes: 0

Views: 568

Answers (1)

Nathan Shively-Sanders
Nathan Shively-Sanders

Reputation: 18389

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.

Upvotes: 2

Related Questions