Lecture Notes on 13 Nov 2020 Graphs * A graph is a network of vertices and edges. * 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 path / cycle (circuit) - visit every edge just once * Hamiltonian path / cycle (circuit) - visit every vertex exactly once * Represent a graph - adjacency matrix - adjacency lists (linked lists) * Graph Traversals * 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.