Undirected graphs presents Graph terminology, Graph representation, How to use the API? Adjacency List Representation, To get adjacent vertices of v in graph, Some graph-processing problems . | Undirected graphs anhtt-fit@ dungct@ Undirected graphs A graph G=(V, E) where V is a set of vertices connected pairwise by edges E. Why study graph algorithms? Interesting and broadly useful abstraction. Challenging branch of computer science and discrete math. Hundreds of graph algorithms known. Thousands of practical applications. Communication, circuits, transportation, scheduling, software systems, internet, games, social network, neural networks, 1 Graph terminology Some graph-processing problems Path: Is there a path between s to t? Shortest path: What is the shortest path between s and t? Cycle: Is there a cycle in the graph? Euler tour: Is there a cycle that uses each edge exactly once? Hamilton tour: Is there a cycle that uses each vertex exactly once? Connectivity: Is there a way to connect all of the vertices? MST: What is the best way to connect all of the vertices? Biconnectivity: Is there a vertex whose removal disconnects the graph? 2 Graph representation (1) Maintain a list of the edges Not suitable for searching Edge List Structure Edge sequence sequence of edge objects Edge object element origin vertex object destination vertex object reference to position in edge sequence Vertex sequence sequence of vertex objects Vertex object – element – reference to position in vertex sequence 3 Graph representation (2) Maintain an adjacency matrix. Suitable for random accesses to the edges A graph data structure Use a dynamic array to represent a graph as the following typedef struct { int * matrix; int sizemax; } Graph; Define the following API Graph createGraph(int sizemax); void setEdge(Graph* graph, int v1, int v2); int connected(Graph* graph, int v1, int v2); int getConnectedVertices(Graph* graph, int vertex, int[] output); // return the number of connected vertices. 4 How to use the API? int i, n, output[100]; Graph g = createGraph(100); addEdge(g, 0, 1); addEdge(g, 0, 2); addEdge(g, 1, 2); addEdge(g, .