Hey there! Sign in to join this conversationNew here? Join for free

Data structure in Java to represent an acyclic directed graph Watch

    • Thread Starter
    Offline

    1
    ReputationRep:
    Hi guys.

    I need to implement a transition network in Java and have found that an acyclic directed graph is probably the best model to use. Problem is that I don't know what the best corresponding data structure in Java would be to represent the graph.

    Any comments would be greatly appreciated!

    Thanks in advance
    Offline

    16
    ReputationRep:
    Code:
    class Graph {
        private Vertex vertices[];
        private Edge edges[];
        ...
    }
    
    class Vertex {
        ...
    }
    
    class Edge {
        private Vertex u;
        private Vertex v;
        ...
    }
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by Planto)
    Code:
    class Graph {
        private Vertex vertices[];
        private Edge edges[];
        ...
    }
    
    class Vertex {
        ...
    }
    
    class Edge {
        private Vertex u;
        private Vertex v;
        ...
    }
    Thanks a lot!

    Is there an actual Java class called Graph or have you created this yourself? Sorry if this is a really stupid question! Haven't done any programming in ages :rolleyes:
    Offline

    16
    ReputationRep:
    I'm not aware of any built-in graph classes but you could always check the documentation. Obviously if you write it yourself you'll also need to write any applicable methods but it shouldn't be too difficult provided you already have whatever algorithms you need.
 
 
 
Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: December 19, 2010
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What newspaper do you read/prefer?
    Useful resources
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.