Problem help (prerequesites problem from topcoder)

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
JackBauer
New poster
Posts: 19
Joined: Sun Mar 21, 2004 8:07 pm

Problem help (prerequesites problem from topcoder)

Post by JackBauer »

Hello,

can someone give me some tips and hints to solve this problem (I don't want no full code or full algorithm)?

This is a problem from top coder. Actually it's a subset of that problem since I just want some ideas and this is the part I have trouble with. The other parts include sorting. If someone is curious about the rest of the statement please say so.

Given a set of "classes" and their prerequesites, for example

Class10: Class01 Class02
Class02: Class01
Class01: (no pre requesite)

And given this the program must create a schedule, that is, an order of classes respecting some rules (if a class A is PR of another Z class, then class A must come before class Z).

To that example above the schedule would be:

result = { "Class01", "Class02", "Class10" }

Another example

Class101: XXX01 YYY02
XXX01: (no ...)
XXX02: (no ...)

Result = "XXX01" "XXX02" "Class101"

The can also be cases where we can't produce a result, as in example

Class01: Class02
Class02: Class01

In this case the program will return an empty list.


Ideas, hints ant tips are welcome :).

Thanks in advance.
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Look up topological sort.
Post Reply

Return to “Algorithms”