I am new to graph theory. I have come across many ways that state implementation of adjacency list representation of a graph in java, which includes:
ArrayList<T>[]
LinkedList<T>[]
ArrayList<ArrayList<T>>
ArrayList<HashSet<T>>
HashMap<Integer, List<T>>
etc.
I want to know which is the best data structure to use for obtaining best time complexity if I require minimum these operations on the graph:
- Find if two nodes are connected by an edge.
- Iterate over all neighbors of particular vertex.
- (Optional) Order all neighbors of a vertex by weight, or maybe like a priority queue.
Can you please guide as which standard library data structure is best for adjacency list implementation of graph in java to get optimum space and time complexity? (time complexity has more priority than space complexity)