Problem 2189. Order of things - 1
Let's assume you have a number of calculations to perform, that depend on each other. E.g. 'A' can be calculated, once the outcome of 'B' is known. And 'C' depends on the results of 'A' and 'D'. 'D' depends on 'A'. 'E' depends on all others. Find the right order of the calculations, needed to get all the results. Assume that only one calculation can be done at a time.
The dependencies of the calculations on each other is expressed in a matrix, where each row and column corresponds to a specific calculation.
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 0 0 0 E 1 1 1 1 0
A '1' indicates that the calculation on that row depends on the one mentioned at the top of that column.
In matrix terms, re-order the rows and columns (the same operation applies to both) such that the upper-right triangle, above the diagonal, only contains zeros.
B A D C E B 0 0 0 0 0 A 1 0 0 0 0 D 0 1 0 0 0 C 0 1 1 0 0 E 1 1 1 1 0
Return the new row/column order as a numeric row-vector, referring to the rows/columns of the input matrix. In this example:
[ 2 1 4 3 5 ]
You may assume that all calculations can be executed, in some order or another.
Solution Stats
Problem Comments
-
2 Comments
Maybe a clue or a link to understand this family of problem.
The background is that I encountered this problem when analysing experimental data. Different acquisition modules were used simultaneously. Timing data from one signal was used to calculate a delay from another. The offset from again another was to be subtracted from a couple of others. An area under a resulting curve was to be devided by another area, taking into account the timing signal. In other words, there were multiple interconnected processing steps, with cross-dependencies.
This inspired me to write this Cody-task.
Solution Comments
Show commentsProblem Recent Solvers18
Suggested Problems
-
840 Solvers
-
76 Solvers
-
Sum the entries of each column of a matrix which satisfy a logical condition.
162 Solvers
-
320 Solvers
-
603 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!