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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:58:52+00:00 2026-06-04T17:58:52+00:00

I’m trying to build a data tree like the one shown below, and I

  • 0

I’m trying to build a data tree like the one shown below, and I need an efficient matching algorithm that can do the following.

You can think of this tree as a list of prerequisites for taking courses. For example, course1 has prerequisite 3 and 4, and course 3 has prerequisites 7 and 8. If one wants to take course1, he/she must take both 3 and 4, or all prerequisites for course3 or course4 (so if he/she took 7,8,4, it’s equivalent to having taken 3 and 4).

Now a kid comes and says he wants to take course2, providing that he took course 8,9 and 6 in advance. How can I quickly check if he is eligible?

The only way I can think of right now is to construct a look-up table that contains all combinations of prerequisites, and checks through it to find the match. However, as the tree grows bigger(I’m trying to build one with potentially >10,000 nodes), this method is going to blow up my computer.

Does anyone have any advice for this? Or better yet, is there a well-defined searching algorithm that can handle this type of task already?
Thanks in advance.
Jim

enter image description here

Fig: Some arbitrary data tree

  • 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-04T17:58:53+00:00Added an answer on June 4, 2026 at 5:58 pm

    Performance will probably be fine just doing it in a simple way. If the student wants 2, first check whether they satisfy the requirements imposed by the 5 prerequisite, then check whether they satisfy the requirements imposed by the 6 prerequisite. You requirements-checking function is going to involve a recursive call or similar.

    If this doesn’t work for some reason (cycles in the graph?!), you could go in the other direction to what you’ve described: start from the courses the student has taken, and flood-fill to get a list of all the courses the student qualifies for. Check whether the target is in that list (or rather: stop immediately if you encounter the target while building the list).

    The flood fill is somewhat complicated by the fact that you’re not just following arrows: I can qualify for 1 in four different ways: (3 or (7 and 8)) and (4 or 9). But the basic idea is the same: keep testing the parents of my reachable nodes to see whether I can add anything to my set, until I can’t any more.

    Applicable to both methods: I’m not entirely clear what the rules are, whether this “satisfying the prerequisites of 3 instead of taking 3” is transitive or not. Given:

          1
         / \
        2   3
       /
      4
     / \
    5   6
    

    I get that having (5,6) qualifies me for 2, but does (5,6,3) qualify me for 1?

    If so then I think the process is a bit easier, because as a simplifying assumption I can just pretend that if I’ve taken (5,6) then I’ve also taken 4, and the question “am I eligible for 2?” becomes, “have I taken 2?”.

    It seems to me more sensible if it doesn’t, since I don’t suppose I can really take a whole bunch of elementary classes and then jump straight into post-graduate work 10 levels higher up. Then there’s a functional difference between courses that I’ve taken, vs courses whose prerequisites I’ve taken. That difference needs to be tracked. In the case of the flood-fill, I think that means 2 flags per node to consider rather than 1. In the case of the requirements-checking function, I think it means you need 2 checks (for direct and indirect satisfaction), and no recursion is needed.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
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 need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.