Problem 2190. Order of things - 2
This 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!
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
Vectorize the digits of an Integer
317 Solvers
-
Are all the three given point in the same line?
414 Solvers
-
Create Volcano (or Atoll) martix. It is an extension of Bullseye matrix problem.
139 Solvers
-
14519 Solvers
-
326 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!