English 中文(简体)
Pseudocode for getting order based on Dependency
原标题:
  • 时间:2009-12-10 16:12:34
  •  标签:
  • pseudocode

Ok, my situation is this I have a list of items and I need to get the order of these items based on the references they have. For example lets say we have these items: A,B,C,D,E,F

C and D have no dependencies so their order can be 0. B is the one that has the most with C, D and A. A has C and F has A and B

  C    D    
  |   /
  A  /
/ | /
| B 
 |
  F

In this case C,D = 0 A = 1 B= 2 F = 3

I have been looking through the internet and it seems I am not using the correct scientific term for this. Most probably it is a Set or a Bag set in some way. I know it is not a tree as this situation has more than two edges on each node. The answer can be in a programming language, just trying to make it as general as possible.

最佳回答

A simple algorithm is as follows.

Iterate the collection, looking for elements which have no dependencies: remember these elements as "the level 0 elements".

Iterate the collection again, looking for elements which may depend on "the level 0 elements" but not on other elements: remember these elements as "the level 1 elements".

Iterate the collection again, looking for elements which may depend on "the level 0 elements" and/or on "the level 1 elements", but not on other elements: remember these elements as "the level 2 elements".

Etc.

Stop when every element has an assigned level.

问题回答

You can create a graph and maintain the pointer counts, or you can use matrix. Search and read some basic idea of graph(math, not computer graph), you can find it is pretty easy.





相关问题
Pseudo codestructure to Mysql?

Can somebody help get the following pseudocode in mysql? The resulting selects in the IF statement all return the same columns (4) and multiple rows (unknown) so that s not really the problem i m ...

Assembler Language Programming

I am trying to write a program that inputs a positive number less than 10 and outputs the sum of the first numbers. For example 5 would be 5+4+3+2+1. The commands are Stop, Load, Store, Add, Sum, ...

Job scheduling problem

I m working on an application where I need to automatically schedule jobs for members on a rotating schedule. I m not very good at explaining rules, so here s some data to help out: Positions: A job ...

Explain this DSP notation

I m trying to implement this extenstion of the Karplus-Strong plucked string algorithm, but I don t understand the notation there used. Maybe it will take years of study, but maybe it won t - maybe ...

Pseudocode for getting order based on Dependency

Ok, my situation is this I have a list of items and I need to get the order of these items based on the references they have. For example lets say we have these items: A,B,C,D,E,F C and D have no ...

热门标签