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 6729169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:15:26+00:00 2026-05-26T10:15:26+00:00

I’m implementing a DFS for a (linked list) Graph. My graph structure example: https://i.stack.imgur.com/8GX7V.png

  • 0

I’m implementing a DFS for a (linked list) Graph.

My graph structure example: https://i.stack.imgur.com/8GX7V.png

As you can see, there are many nodes named “a”. They’re the same in terms of vertex but they’re actually different in terms of node. Implementing DFS involves marking “a” as visited at some point. This seems easy but I hope you can see my problem here. There are many “a” to mark as visited. I hope I’m doing something wrong here.

Problem:
– First mark “a” as visited and push it onto stack s. this effectively mark node “a” in the 1st adjacency linked list as visited but all other nodes “a” in other adjacency linked lists are still marked as “not visited”.
– Then consider “b” as it is the first unvisited adjacent vertex to “a”. mark it as visited and push it onto the stack s.
– Now we’re exploring “b”. From the 2nd adjacency linked list, The adjacent vertex to “b” is “a” and this one is unvisited, so we push it onto the stack again. Wrong!

Of course, I can write a markVisit($vertex) method which mark all occurrences of “a” as visited at once, but I don’t think I have the right approach in my implementation above. Thanks for your help.

  • 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-26T10:15:27+00:00Added an answer on May 26, 2026 at 10:15 am

    markVisit($vertex) should be correct, you need to remember which vertexes you already visited. DFS concerns vertexes, not edges.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
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 to count how many characters a certain string has in PHP, but
Specifically, suppose I start with the string string =hello \'i am \' me And

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.