1

enter image description here

What algorithm with recursion I need to use to traverse this graph and get this sequence (Output):

IF01
IF04
IF02
IF03
IF08 
IF05 
IF06 
IF07 
IF09 

Initial data (Input) (first is code, second is how much codes you have, third one is what code you have to take in order to use it, for example to print IF02, you have to have already printed IF01, to print IF05, you have to print IF04 before. and so on)

IF01 0
IF02 1 IF01
IF03 2 IF01 IF02
IF04 0
IF05 1 IF04
IF06 1 IF05
IF07 2 IF03 IF06
IF08 1 IF03
IF09 2 IF07 IF08
2
  • what is the meaning of the array? what is the relations between the nodes and the meaning of the edges? you have to give us more that input/output to help you Commented Feb 21, 2016 at 10:59
  • I have all this data stored in arrays. Edit: Added input Commented Feb 21, 2016 at 11:10

1 Answer 1

1

The most trivial solution to this problem I can think of is to run Topological Sorting, you can see the algorithm here: https://en.wikipedia.org/wiki/Topological_sorting

It should be no problem to implement it in c#

Here's a great article that contains implementation:

http://www.codeproject.com/Articles/869059/Topological-sorting-in-Csharp

Sign up to request clarification or add additional context in comments.

6 Comments

You're right, that's the algorithm! But I have no idea how to implement it using arrays and not lists or dictionaries.
@Seinioritza I've added a great article that has implementation
Yes, I saw it. But problem is that I need to use arrays
is there a special reason to use array and not list? Also bear in mind you always can convert array to list and vice versa
Yes, I need to do it only using arrays and I never used list before.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.