topological-sort

How to sort a list of inter-linked tuples?

穿精又带淫゛_ 提交于 2021-02-07 08:56:04
问题 lst = [(u'course', u'session'), (u'instructor', u'session'), (u'session', u'trainee'), (u'person', u'trainee'), (u'person', u'instructor'), (u'course', u'instructor')] I've above list of tuple, I need to sort it with following logic.... each tuple's 2nd element is dependent on 1st element, e.g. (course, session) -> session is dependent on course and so on.. I want a sorted list based on priority of their dependency, less or independent object will come first so output should be like below,

How to sort a list of inter-linked tuples?

青春壹個敷衍的年華 提交于 2021-02-07 08:55:42
问题 lst = [(u'course', u'session'), (u'instructor', u'session'), (u'session', u'trainee'), (u'person', u'trainee'), (u'person', u'instructor'), (u'course', u'instructor')] I've above list of tuple, I need to sort it with following logic.... each tuple's 2nd element is dependent on 1st element, e.g. (course, session) -> session is dependent on course and so on.. I want a sorted list based on priority of their dependency, less or independent object will come first so output should be like below,

How to sort a list of inter-linked tuples?

家住魔仙堡 提交于 2021-02-07 08:53:50
问题 lst = [(u'course', u'session'), (u'instructor', u'session'), (u'session', u'trainee'), (u'person', u'trainee'), (u'person', u'instructor'), (u'course', u'instructor')] I've above list of tuple, I need to sort it with following logic.... each tuple's 2nd element is dependent on 1st element, e.g. (course, session) -> session is dependent on course and so on.. I want a sorted list based on priority of their dependency, less or independent object will come first so output should be like below,

How to sort objects? (painters algorithm)

喜你入骨 提交于 2020-02-03 10:53:21
问题 So I got 4 rectangular shapes and I'm trying to apply a sorting algorithm (painters algorithm) to know which shapes (in 3d) I need to draw first and which one after. Note : The camera is in the bottom right corner: The correct order would be: purple, red, blue, green (for drawing of course reversed order). So I've implemented an algorithm which creates something like this: Theres every object listed with it's correct successors and predecessors . ITEM: red predecessor: - successor: - ITEM:

What is the best way to sort a partially ordered list?

断了今生、忘了曾经 提交于 2020-01-10 19:33:59
问题 Probably best illustrated with a small example. Given the relations A < B < C A < P < Q Correct outputs would be ABCPQ or APQBC or APBCQ ... etc. In other words, any ordering is valid in which the given relationships hold. I am most interested in the solution that is easiest to implement, but the best O(n) in speed and time is interesting as well. 回答1: This is called topological sorting. The standard algorithm is to output a minimal element, then remove it and repeat until done. 回答2: Do

What is the best way to sort a partially ordered list?

给你一囗甜甜゛ 提交于 2020-01-10 19:33:32
问题 Probably best illustrated with a small example. Given the relations A < B < C A < P < Q Correct outputs would be ABCPQ or APQBC or APBCQ ... etc. In other words, any ordering is valid in which the given relationships hold. I am most interested in the solution that is easiest to implement, but the best O(n) in speed and time is interesting as well. 回答1: This is called topological sorting. The standard algorithm is to output a minimal element, then remove it and repeat until done. 回答2: Do

random algorithm over all topological sorts of a DAG?

混江龙づ霸主 提交于 2020-01-01 03:26:10
问题 Does anyone know of a random algorithm for generating a topological sort of a DAG, where each invocation of the algorithm has a non-zero probability of generating every valid topological sort of the DAG. It's crucial that the algorithm does not preclude any valid topological sort, because it's part of a larger algorithm that, given enough iterations, must be demonstrably capable of exploring all topological sorts of a given DAG. Does anyone know if such an algorithm has been developed?

Python: sorting a dependency list

匆匆过客 提交于 2019-12-29 05:16:08
问题 I'm trying to work out if my problem is solvable using the builtin sorted() function or if I need to do myself - old school using cmp would have been relatively easy. My data-set looks like: x = [ ('business', Set('fleet','address')) ('device', Set('business','model','status','pack')) ('txn', Set('device','business','operator')) .... The sort rule should be basically for all value of N & Y where Y > N, x[N][0] not in x[Y][1] Although I'm using Python 2.6 where the cmp argument is still

Determine whether a directed graph has a unique topological ordering?

扶醉桌前 提交于 2019-12-24 11:30:15
问题 I'm trying to create pseudo-code for an algorithm that will be able to determine whether a directed graph has a unique topological ordering. I've already come up with the following pseudo-code for a topological sort, but what would I have to add or edit in order to determine whether a digraph has a unique topological ordering? Input: A graph G Output: A list L that contain the sorted vertices define an empty list L; create a stack Stack; push all vertices with no incoming edges into Stack;