Goldman Sachs Interview Question
Software Engineer / Developersby representing it in graph:
A-->B
| |
v v
C D ( v is actually arrow mark ! )
Apply topological sort:
We get 3 possible orderings:
A-->B-->C-->D
A-->B-->D-->C
A-->C-->B-->D
so, it can be either B or C
To compute a topological ordering of G:
Find a node v with no incoming edges and order it first
Delete v from G
Recursively compute a topological ordering of G-{v}
and append this order after v
Use topologically sorted graph
- Abhijit Mehta June 20, 2009