Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7407047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:38:58+00:00 2026-05-29T05:38:58+00:00

I’m new to Scheme, have been using MIT Scheme for sometime now. I’m trying

  • 0

I’m new to Scheme, have been using MIT Scheme for sometime now. I’m trying to understand how to implement popular graph algorithms like the shortest path algorithms, BFS, DFS. Are there any tutorials that could help me out understand the recursion that’d be involved, along with the appropriate data structures? I have tried Googling my way around, but that didn’t end up giving me good results.

EDIT: I apologize for not being more specific earlier. My question was pertaining to traversing the whole graph, and not finding the path between a start and goal node. So, given a graph G(V, E), where V is the vertex set and E is the edge set, starting from any node n, what is the path generated so that at the end of this traversal, all nodes are visited.

Most implementations that I found while Googling were the ones with the start and goal node. My version (one of the answers), chooses one vertex, and visits all others.

Take for example, the following graph:-

1 ----> 2           5
       /|          /|
      / |         / |
     /  |        /  |
    /   |       /   |
   /    |      /    | 
  4<----3 <---6     7

This DAG has (4->2), (2->3), (5->6) and (5->7), which I unable to represent in the diagram. 🙂

The Path traversed starting from 1 could be:

(1, 2, 3, 4, 5, 6, 7)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:38:58+00:00Added an answer on May 29, 2026 at 5:38 am

    Took some time, but I got it working finally! My output is the sequence in which the nodes would’ve been visited in the traversal through DFS.

    Note that I am still only learning Scheme, and my programming approach might not be the best. If you find something wrong, incorrect or something that can be expressed better, leave a comment!

        (define (dfs graph)
           (define (dfshelper g unvisited stack path)
              (cond
                 ((null? unvisited) path)
                    ((null? stack)
                       (dfshelper g
                                  unvisited 
                                  (append (list (caar unvisited)) stack) 
                                  path))
                    ((memq (car stack) path) (dfshelper g
                                                        unvisited 
                                                        (cdr stack) 
                                                        path))
                    (else (dfshelper g
                                     (cdr unvisited) 
                                     (append (car (neighbours (car stack) g)) (cdr stack)) 
                                     (append path (list (car stack)))))))
    
       (define (neighbours node g)
          (cond
             ((null? g) '())
             ((equal? node (caar g)) (cdar g))
             (else (neighbours node 
                               (cdr g)))))
    
       (dfshelper graph  graph '() '()))
    

    Sample input could be: (dfs ‘((1 (2)) (2 (3)) (3 (4)) (4 (2)) (5 (3 6)) (6 ())))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.