Home:ALL Converter>Traverse up a directed graph in c# (DAG)

Traverse up a directed graph in c# (DAG)

Ask Time:2021-09-22T05:21:00         Author:HelloWorld

Json Formatter

I have a simple graph without cycles/Multiple edges.

Its always pointing down.

enter image description here

I have a list of edge instances and they are sorted top to down according to their appearance in the graph image. I do not know whether that is important for you. I just thought how would you know what is the node at the bottom of the graph?!

class Edge
   public string FromNodeId {get; set;}
   public string ToNodeId{get; set;}

class Node
   public int Id {get; set;}
   public string Name {get; set;}

I need to traverse UP the graph due to certain business logic.

  1. What is the algorythm called when I need to visit every node in a recursive way?
  2. What could be a starting point to iterate the list of edges recursively up the graph?

Author:HelloWorld,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275681/traverse-up-a-directed-graph-in-c-sharp-dag