Is the example in the problem statement an undirected graph?

  • 3

    The example graph is:

    where 0 has neighbors 1 and 2, but 1 only has 2 as the its neighbor (here 0 is not listed as its neighbor!) --- this is actually a directed graph. In other words, the undirected graph in this case should be:

    Any comments?

  • 0

    Yes, if 1's neighbor is 2 than 2's neighbor should be one.

  • 0

    What {0,1,2#1,2#2,2} means is that every edge is stored once. It is therefore not possible to have {0,1,2#1,2,0#2,0,1,2}.

  • 0

    Not really directed, it just doesn't duplicates the edges. It's different because
    using the representation provided we can have different node structure if we
    change the order in which each node is constructed,which is not true for directed

    However, I do think saving duplicated edges makes more sense.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.