Graph Algorithms
Graph algorithms that we will look at include:
£
Searching for a path between two nodes.- Can be used in game playing, AI, routefinding, ..
£
Finding shortest path between two nodes.
£
Finding a possible
ordering
of nodes givensome constraints.- e.g., finding order of modules to take; order of actions to complete a task.
5
More Terminology
Need to be familiar with a number of terms, whichcan be explained graphically: directed/undirected;cyclic/acyclic; labelled; connected/unconnected;adjacent; neighbours; path;
6
Graphs and Trees
Graphs are more general than trees. (Trees are aspecial kind of connected graph, with no cycles anda “root”).Tree terminology: children, parents, ancestors,siblings, decendants, root, leaf.
7
A Graph ADT: Operations
Need to define:
¤
Operations for modifying and inspecting graph.
¤
Data structure for graph itself.For simple
undirected
,
unlabelled
graph, a small setof operations is enough, to:
¤
Create a graph.
¤
Add and remove edges to the graph.
¤
Check if an edge exists.If we assume all nodes are indentified by a number,following C++ functions can be used:
graph(); // constructor˜graph(); // and destructor// (may be empty)void addedge(int n1, int n2);void removedge(int n1, int n2);logical edgeexists(int n1, int n2);
8
Leave a Comment