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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:29:26+00:00 2026-06-15T15:29:26+00:00

I am trying to write a program using a directed graph (which I know

  • 0

I am trying to write a program using a directed graph (which I know about but have never implemented) to simulate a network of transportation.

The user will input a planet name followed by an integer representing the number of total nodes in the graph. The user will then go through each node one by one. They will give it a name give the number of neighbors that node has and then the specific names. The input will look like this.

some_planet 4
node1 2 node2 node3
node2 1 node4
node3 1 node4
node4 1 node1

I then just output which nodes node1 cannot reach. However, I have some questions about implementing this.

1) The big one is storing this stuff. What is an easy way? I thinking about a LinkedList and thought I would link the locations. Then I could pop pointers onto them corresponding to whatever the input is. However, I have no idea how to do the last part.

2) The next big one is searching the graph. I was planning on a recursive depth-first-search . Is there anything wrong with this algorithm that you see? I need to search for every node individually this way though so I will have to increment this. Can I just throw everything in a for loop?

recursive-d-first-search(graph G, node start, node find)
  if(start == find)
    return true;

  else
    for every neighbor n of start
      success = recursive-d-first-search(graph G, node n, node find);
      if(success)
        return true;

  return false;
  • 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-06-15T15:29:27+00:00Added an answer on June 15, 2026 at 3:29 pm
    1. I think you just need to use adjacency matrix to store whole graph’s connection relation.
      in your case, it should be like:

          1    2    3    4
      
      1   0    1    1    0
      
      2   0    0    0    1
      
      3   0    0    0    1
      
      4   1    0    0    0
      
    2. If you use adjacency matrix, I think the breadth-first search may be a good choice, because it’s easy to understand and implement. Meanwhile, you need one queue to store next nodes to be checked, and one list to store which nodes have already been checked

      For example, you want to check which nodes node1 cannot reach, you just check row 1 and see that it has 2 and 3, and put 2 and 3 to queue. Then check row 2 to see that it has 4, put 2 to list, and put 4 to queue. Then just use a for loop to do the same operation.

      In the end, you just need to check which nodes are not in list.

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

Sidebar

Related Questions

now, i'm trying to write program using php and sqlite, but i have problem.
I'm trying to write a small baseball statistics program using data from retrosheet.org, but
I am trying to write a python program using Python 3 I have to
I am trying to write a program using python-fuse, but I can't get file
I am trying to write a simple program using Lucene 2.9.4 which searches for
I'm trying to write an interface around my program (using qt). Basically I have
I am trying to write a program which access web pages using Apache HttpClient
I'm trying to write a program using MPI and I have a question that
I'm trying to write a rather trivial program using open gl on linux, but
I am trying to write a program using rtmpsrc plugin which comes under bad

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.