An adjacency list representation as a graph is shown here,
I am fairly new to Scala, and so this is fairly trivial I am assuming. I want to represent my graph in Scala as an adjacency list but edges should have a weight. So I was thinking having a tuple for each entry in the adjacency list for each vertex, where the tuple is the vertex and the edge cost. Hopefully this makes sense. I just want to know how to write this graph representation to a val.
A -> [(B, 1), (C, 1), (D, 1)]
B -> [(A, 1), (C, 2), (D, 2)]
C -> [(A, 1), (B, 2)]
D -> [(A, 1), (B, 2)]
How would I write this as a val in Scala?
val adjList = List(List(("b", 1), ("c", 1), ("d", 1)), List(...), List(...), List(...))
The types are inferred for your to be
List[List[(String, Int)]]. You can manually specify them if you wish but it is not required.