implementing a graph

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bucketbot
    New Member
    • May 2007
    • 9

    implementing a graph

    Can anyone explain how to code a graph based on a priority queue? As in, what would I need to do in order to successfully implement a graph? thanks
  • bucketbot
    New Member
    • May 2007
    • 9

    #2
    Originally posted by bucketbot
    Can anyone explain how to code a graph based on a priority queue? As in, what would I need to do in order to successfully implement a graph? thanks
    i forgot to mention that the graph needs to be an adjacency list, and that it should be implemented with an ArrayList

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by bucketbot
      i forgot to mention that the graph needs to be an adjacency list, and that it should be implemented with an ArrayList
      I'm sorry, I think I don't understand your question. What have priority queues
      to do with graphs? Do you have to build your adjacency matrix yourself or is
      that given already? What do you want to do with that graph?

      kind regards,

      Jos

      Comment

      • bucketbot
        New Member
        • May 2007
        • 9

        #4
        Originally posted by JosAH
        I'm sorry, I think I don't understand your question. What have priority queues
        to do with graphs? Do you have to build your adjacency matrix yourself or is
        that given already? What do you want to do with that graph?

        kind regards,

        Jos

        we constructed a min-heap based priority queue, and now we have to design a graph (for use with Dijkstras algorithm) using that PQ. I just don't understand how to construct the graph. So far, I have a Graph class, a Vertex class, and an Edge class. If my vertex class is simply a name and an array of incident edges, then what is my Edge class?

        the end product is suppose to be something that reads in input (in this case, a sort of map), and it has to determine which path has the shortest distance or shortest time to travel.

        thanks

        Comment

        • prometheuzz
          Recognized Expert New Member
          • Apr 2007
          • 197

          #5
          Originally posted by bucketbot
          ...

          I just don't understand how to construct the graph. So far, I have a Graph class, a Vertex class, and an Edge class. If my vertex class is simply a name and an array of incident edges, then what is my Edge class?

          ...
          An Edge class isn't necessary. Just use a java.util.List in your Vertex class that holds references to the neighbouring Vertices.
          And your Graph class has a java.util.List with Vertex objects of course.

          Another approach is to use an implementation of a java.util.Map<K ey, Value>,where the key is a (unique) Vertex and the value is a java.util.List containing the Vertex's neighbours.

          Good luck.

          Comment

          Working...