[an error occurred while processing this directive]
**cs205 Data Abstraction Notes**

(Repeated from Class 8)

#### Upcoming Schedule

- Every week: there are scheduled lab hours in Small Hall on: Sundays
(7-8pm), Mondays (6-7pm), and Thursdays (5-6pm). I have office hours
(in Olsson 236D) on Thursdays, 10:30am-noon.
- Friday, 15 September: quiz 2 (originally scheduled for Monday,
11 September)
- Monday, 18 September: problem set 3

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:
// this_{post} = < Nodes_{pre}, Edges_{pre} 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 }
}

- Select a representation for Graph. Consider carefully several
different possible representations, and what their advantages and
disadvantages will be.
- Determine the rep invariant and abstraction function
- Implement
`Graph ()`, `addNode` and `hasHode`
- Implement
`addEdge` and `getNeighbors`