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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:26:44+00:00 2026-06-01T03:26:44+00:00

I am amateur programmer learning how to program. I have never had any computer

  • 0

I am amateur programmer learning how to program.
I have never had any computer science courses so I have hard times with this trivial problem:

class Room {
    String name;
    ArrayList<Room> neighbors = new ArrayList<Room>();

    // constructor with name
    // getters
    void addNeighbor(Room room) {
        neighbors.add(room);
    }
}

class Finder {
    void findShortestPath(Room start, Room end) {
        // ?
    }
}

Every room has some neighbors. More then 4, so it’s not like matrix oriented problem. You are given end room and you must find shortest path from the start room (comparing the names of the rooms). Result should be “way” like:

Start: Kitchen

End: Toilet

Path: Kitchen, Living Room, Corridor, Bedroom, Toilet

I think I must use some recursion for the rooms and I think I should save where I have already been in some stack. But I don’t really know how to start.

Can some of you CS guys help me? Thanks

  • 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-01T03:26:46+00:00Added an answer on June 1, 2026 at 3:26 am

    You are looking for BFS.

    In your case, the graph G = (V,E) is actually V= { all rooms } and E = {(u,v), (v,u) | u and v are neighboring rooms }

    Note that you don’t care you don’t have all edges [neighbors] before the algorithm starts – you know how to calculate the relevant set of edges [and rooms] on the fly, using the neighbors field.

    This is true since every “edge” you need to use for your path – was “discovered” when you discovered the room which is closer in the path to the source.

    You can have a look at this post – how you can find the actual path after running a BFS.

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

Sidebar

Related Questions

Ok, I am an amateur programmer and just wrote this. It gets the job
I'm an amateur C++ programmer trying to learn about basic shell scripting. I have
I'm still learning Objective-C so forgive me if this is a simple amateur mistake,
Hey, Sorry if this is a dumb question. I'm an amateur programmer and new
Alright I know this is more than likely a amateur question but I have
As an amateur mobile developer, I feel dismay every time I have to fix,
I know this is probably a really amateur question, but I can't figure this
Let me preface this by saying I'm a complete amateur when it comes to
I am an amateur programmer. When I publish an app from Visual Studio Express,
So I tried searching SO hoping someone had a good explanation of this, with

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.