0

I need a graph data structure implementation that stores a graph with vertices and edges, but my edges need to be objects that can store their own data, unlike just the normal adjacency list implementations.

I remember seeing such a representation for this once, but can not find it now.

It kept a list or map of vertexes and a list or map of edges objects. Can anyone point me to a good reference for this?

professor.jenkins
  • 155
  • 1
  • 1
  • 8
  • So which programming language are you looking into? Python, Java, C++, javascript etc? Unless you're looking for pseudo code – Haris Nadeem May 12 '18 at 18:57
  • pseudo code or just diagram is fine. I will be implementing in python but I am fluent in most languages, so an example in C, C++, Go, Rails, Java, Python, etc would be great! – professor.jenkins May 12 '18 at 22:08
  • I think you should look here and tell me if this does/doesnt answer your question. https://stackoverflow.com/questions/19472530/representing-graphs-data-structure-in-python – Haris Nadeem May 13 '18 at 00:10
  • I looked at your refrence, and this is not what I am looking for. The original reference I saw was showing a general diagram to store both vertex object list, and a edge list with associated data. I am not interested in a using module or existing library but the actual technique for the structure. – professor.jenkins May 13 '18 at 04:45

1 Answers1

1

You could define an Edge class with all the data you need and then have an adjency list whose values aren't vertices but Edge object (which store from, to vertices).

If you don't want the Edge class to have vertices properties, you could put tuples of (Edge, vertice) in your adjency list instead.

  • Thank you, I ended up creating a python solution storing edge tuple keys normalized for undirected graphs see code at: https://gist.github.com/gerryjenkinslb/40cc77e72ef96e3446955dbfb9f00f80 – professor.jenkins May 15 '18 at 19:45