Graphs
Problems such as the farmer, wolf, goat, and cabbage (FWGC) problem are
characterized by searching a space of states.
We can build a structure that represents all the possible transitions from
one state to another in the FWGC problem.
A graph is a structure that can be characterized as a set of objects
called vertices (also nodes) that are connected
by edges.
Examples of things that can be represented as graphs:
|
Vertices |
Edges |
FWGC Problem |
States |
Moves |
UML Diagrams |
Classes |
Class Relationships |
JavaFX Scene |
Nodes |
Hierarchy Relationships |
Maps |
Cities |
Roads |
Circuits |
Transistors |
Wires |
Networks |
Computers |
Cables |
Social Networks |
People |
Relationships |
This section describes adjacency list representation for undirected
and directed graphs.
Q: How might we represent the FWGC problem with a graph?
- Both of our graph representation methods, adjacency list
and adjacency matrix, require using a vertex number to index
into an array.
- However, we don't have a vertex number; we have a Java object that is
an instance of a class that implements the State interface, for
example, FarmerState.
Q: So, how can we look up information about a Java object
quickly, like indexing into an array?
A: Use a
hash table.