[an error occurred while processing this directive]

cs205 Data Abstraction Notes
(Repeated from Class 8)

Upcoming Schedule

public class Graph {
   // OVERVIEW: A Graph is a mutable type that represents an undirected
   //      graph.  It consists of nodes that are named by Strings,
   //      and edges that connect a pair of nodes.
   //      A typical Graph is: < Nodes, Edges > where
   //         Nodes = { n1, n2, , nm }
   //       and 
   //         Edges = { {a_1, b_1}, ..., {a_n, b_n} }
   //         (note that the elements of Edges are unordered sets)

   public Graph () 
      // EFFECTS: Initializes this to a graph
      //      with no nodes or edges: < {}, {} >.

   // Mutators
   public void addNode (String name) throws DuplicateException
      // MODIFIES: this
      // EFFECTS: If name is in Nodes, throws DuplicateException.
      //    Otherwise, adds a node named name to this:
      //     this_post = < Nodes_pre U { name }, Edges_pre >

   public void addEdge (String fnode, String tnode) throws
      NoNodeException, DuplicateException
      // MODIFIES: this
      // EFFECTS: If s and t are not names of nodes in
      //    this, throws NoNodeException.  If there is already an edge
      //    between s and t, throws DuplicateEdgeException.
      //    Otherwise, adds an edge between s and t to this:
      //      thispost = < Nodespre, Edgespre U {fnode, tnode} >

   // Observers
   public boolean hasNode (String node)
      // EFFECTS: Returns true iff node is a node in this.

   Set getNeighbors (String node)
      // REQUIRES: node is a node in this
      // EFFECTS: Returns the set consisting of all nodes in this
      //      that are directly connected to node:
      //         { n | {node, n} is in this.edges }
  1. Select a representation for Graph. Consider carefully several different possible representations, and what their advantages and disadvantages will be.
  2. Determine the rep invariant and abstraction function
  3. Implement Graph (), addNode and hasHode
  4. Implement addEdge and getNeighbors