The best option is the adjacency list, you need to google in this direction. In short, you need something like this:
int n = 10000; // колчество записей List<List<int>> a = new List<List<int>>(n); foreach ( /* перебрать все записи */) { // parent_id - id родителя // child_id - id ребёнка a[parent_id].Add(child_id); a[child_id].Add(parent_id); }
Here a [i] is the list of those vertices that are adjacent to vertex i. But it is necessary to decide whether the graph is oriented or not. If the graph is oriented, then it is necessary to add only the edges from the parent to the descendant, or only from the descendant to the parent (depending on what then to do with this graph). If the graph is undirected, then both edges must be added
The adjacency matrix is not suitable due to the fact that you need an array of size 10 ^ 8