Lecture Notes on 08 Apr 2022 Graphs * A graph is a network of vertices and edges. * In 1736 Leonhard Euler presented the solution to the Bridges of Konigsberg (now Kaliningard) problem - this was the beginning of Graph Theory https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/misc/Konigsberg_Bridges.png * Types of Graphs - (un) weighted, (un) directed - (dis) connected - (in) complete - (a) cyclic - bipartite * Degree of a vertex - number of edges that are incident on the vertex * Eulerian cycle (circuit) - visit every edge just once and return to the starting vertex. * Hamiltonian cycle (circuit) - visit every vertex exactly once and return to the starting vertex. * The Eulerian Path or Hamiltonian Path differs from the cycle in that the starting and ending vertices are different. * Graph Representation - adjacency matrix - adjacency lists (linked lists) https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Graph_Representation.pdf * Graph Exercise: - Download the map of the towns in Virginia https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Virginia.pdf - Download the spreadsheet and create the adjacency matrix https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Virginia_Towns.xlsx https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Virginia_Towns.pdf - Create the adjacency list for the towns in Virginia * Graph Traversals - depth first search (dfs) - breadth first search (bfs) * Depth First Search (DFS) 0. Create a Stack. 1. Select a starting vertex. Make it the current vertex. Mark it visited. Push it on the stack. 2. If possible, visit an adjacent unvisited vertex from the current vertex in order. Make it the current vertez. Mark it visited, and push it on the stack. 3. If you cannot follow step 2, then if possible pop a vertex from the stack. Make it the current vertex. 4. Repeat steps 2 and 3 until the stack is empty. * Breadth First Search (BFS) 0. Create a Queue. 1. Select a starting vertex. Make it the current vertex. Mark it visited. 2. Visit an adjacent unvisited vertex (if there is one) in order from the current vertex. Mark it visited and insert it into the queue. 3. If you cannot carry out step 2 because there are no more unvisited vertices, remove a vertex from the queue (if possible) and make it the current vertex. 4. Repeat steps 2 and 3 until the queue is empty. * Definitions - bipartite and isomorphism https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Graph_Terms.pdf https://www.cs.utexas.edu/users/mitra/csSpring2022/cs313/notes/Graph_Images.pdf