Java - Which is the best implementation structure for Graph?

前端 未结 8 2085
我在风中等你
我在风中等你 2021-02-02 16:47

The graph is very large but undirected. Edges are unweighted.

In my implementation, I have to find the vertex with max degree and do deletion on both vertexes and edges.

8条回答
  •  走了就别回头了
    2021-02-02 17:13

    If your algorithm requires looking up on max degree, then you want a data structure ordered by degree, something like a PriorityQueue would be good.

    Then you need to store the graph itself. For deletion quickly I'd recommend something like a Sparse Array structure. If you have to use java.util data structures, then a HashMap from vertexes to the list of connected vertexes offers O(1) deletion.

    If you could use 3rd party libraries, then there are a list of answers here of which JGraph and JUNG seem most popular.

提交回复
热议问题