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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:15:54+00:00 2026-06-18T00:15:54+00:00

I have data in database which is in the form of: A -> B

  • 0

I have data in database which is in the form of:

A -> B
C -> D
B -> C
F -> G
G -> J
X -> Z

This basically means that A goes to B, C goes to D etc. Given this data and a node (such as C) I would like to construct the complete path that C is found that is A -> B -> C -> D . I tried to do this by using a few dictionaries and recursive loops but I don’t like such a sluggish solution since there are lots of data in db. What is a better way to solve this problem ? In terms of both algorithm and the data structure ? Any ideas or hints are appreciated.

  • 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-18T00:15:55+00:00Added an answer on June 18, 2026 at 12:15 am

    You are looking basically for DFS, but you need to do it twice – one per direction.

    First do a a DFS on the reverse ‘graph’, starting from C.

    In your example it will give you Path1 = C->B->A

    Next, do a DFS on the original graph, again from C.

    In your example it will give you Path2= C->D

    Now, by reversing Path1, and concatinating Path2 to it you will get:

    reverse(Path1)  + Path2 = A->B->C + C->D = A->B->C->D
    

    Clarification – DFS is just abstraction, what you actually are doing is something similar to (pseudo code):

    current <- C
    list = []
    while (current != null):
       list.addFirst(current)
       current <- u such that (u,current) is in the DataBase
    current <- C
    list.deleteLast() // last is C
    while (current != null):
       list.addLast(current)
       current <- u such that (current,u) is in the DataBase
    

    Note that finding u both cases is a simple dictionary look up, in the first the “Target” is the key, and in the second the “Source” is the key.

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

Sidebar

Related Questions

I have this jquery.ajax form which populates data from the database and auto fills
I have a MySQL database which contains data i would like to populate into
I have a ton of data in a sql database which I would like
I have a SQL Server 2008 database which contains data that I need to
I have created an application which inserts data into a SQL database. Basically, from
I have data in an SQL Server 2005 database which I need to copy
I have a sqlite3 database in which I have corrupt data. I qualify corrupt
I have a database which contains picture data stored as a binary blob. The
I have a database which users should not be able to alter data in
I have a database which I regularly need to import large amounts of data

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.