MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply TodayThis problem is closely related to Problem 2189, Order of things - 1. For the details, see the description for that problem. Basically, we have to find the order in which to execute tasks of which the results and prerequisites depend on each other.

- However, this time it may be impossible to find a solution, since dependencies may be cyclic. In that case, return an empty vector.
- Furthermore, if there are multiple orders possible, return them as multiple rows of the output vector.

Again, the dependencies of the tasks on each other is expressed in a matrix, where each row and column corresponds to a specific task. Each row expresses on which result that task depends. A `1` indicates that the calculation on that row depends on the one mentioned at the top of that column.

Return the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. Of an empty array when no solution is possible. Or a matrix of rows containing the orders, where each row is a different solution, in case multiple solutions exist.

A B C D E A 0 1 0 0 0 B 0 0 0 0 0 C 1 0 0 1 0 D 1 0 1 0 0 E 1 1 1 1 0

The above problem can not be solved, since `C` depends on `D`, which in its place depends on `C`. The returned value would be `[]` .

A B C D E A 0 1 0 0 0 B 0 0 0 0 0 C 1 0 0 0 0 D 1 0 0 0 0 E 1 1 1 1 0

The returned matrix should be

[ 2 1 3 4 5 2 1 4 3 5 ]

Good luck!

7 correct solutions
1 incorrect solutions

Last solution submitted on Oct 10, 2015

1 player likes this solution

1 Comment