How to represent a strange graph in some data structure

后端 未结 3 1280
执念已碎
执念已碎 2021-02-03 11:23

A simple way to represent a graph is with a data structure of the form:

{1:[2,3],
 2:[1,3],
 3:[1,2]}

Where the keys in this dictionary are nod

3条回答
  •  醉梦人生
    2021-02-03 11:51

    You could implement it as a basic graph with nodes and edges. In each node, store a list of edges. For each of those edges, store a mapping from that "entry" edge, to the valid exit edges.

    I should point out that the image you posted isn't a graph, since A, F, and D do not connect to any nodes (unless they're just off-screen).

提交回复
热议问题