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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:53:38+00:00 2026-06-01T09:53:38+00:00

What algorithm would you use to create an application that given appropriate data (list

  • 0

What algorithm would you use to create an application that given appropriate data (list of cities, train routes, train stations) is capable of returning a list of connection between any two user-selected cities? The application has to choose only those connections that fall into the limit of accepted train-changes.

Example: I ask the application which train to take if I need to travel from Paris to Moscow with max. 1 stop/switch – the application returns a route: Train 1 (Paris-Berlin) -> Train 2 (Berlin->Moscow) (No direct connection exists).

Graphical example Map

https://i.stack.imgur.com/NSP9y.png

If I ask the system about possible connections from Town A to Town G I get a response:

  • Brown Line (0 switches = direct)
  • Brown Line to Town B / Orange Line to Town G (1 switch)
  • Brown Line to Town B / Orange Line to Town D / Red Line to G (2 switch)
  • … all other possibilities

And thouh the 2nd and 3rd options are shorter than the 1st, it’s the 1st that should have priority (since no train-switching is involved).

  • 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-01T09:53:39+00:00Added an answer on June 1, 2026 at 9:53 am

    Assuming the only thing important is “number of stops/switches”, then the problem is actually finding a shortest path in an unweighted directed graph.

    The graph model is G = (V,E) where V = {all possible stations} and E = { (u,v) | there is a train/route from station u to station v }

    Note: let’s say you have a train which starts at a_0, and paths through a_1, a_2,…a_n: then E will contain: (a_0,a_1),(a_0,a_2),..,(a_0,a_n) and also (a_1,a_2),(a_1,a_3),... formally: for each i < j : (a_i,a_j) ∈ E.

    BFS solves this problem, and is both complete [always finds a solution if there is one] and optimal [finds the shortest path].

    If the edges [routes] are weighted, something like dijkstra’s algorithm will be needed instead.

    If you want a list of all possible routes, Iterative-Deepening DFS could be used, without maintaining a visited set, and print all the paths found to the target up to the relevant depth. [BFS fails to return all paths with the counter example of a clique]

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

Sidebar

Related Questions

I am looking for a sound algorithm that would randomly place a given number
Which algorithm would you use to search short substrings in short texts? By short
What algorithm would you make a computer use, if you want to solve a
What would be the best compression algorithm to use to compress packets before sending
On SO 18 Joel mentioned an algorithm that would rank items based on their
A friend was in need of an algorithm that would let him loop through
What would be the best algorithm for finding a number that occurs only once
I'm trying to write an application that can be used to create pictures that
I want to create a class that can use one of four algorithms (and
I have a java application that streams raw data and draws real time plots

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.