Search code examples
algorithmsortingdata-structuresgraph-algorithmstoring-data

I need to know which algorithm i should choose for following situation


i have four component A,B,C,D. which Dependency flow like A -> B -> C -> D. A is dependent on B and B is on C and C is on D. what type of algorithm i should use in this situation.


Solution

  • The algorithm for which you are looking for is Topological sort.

    Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of
    vertices such that for every directed edge u-v, vertex u comes before v in the 
    ordering. Topological Sorting for a graph is not possible if the graph is not 
    a DAG.