1 / 74

Assignment 2 Remarking

This assignment discusses directed and undirected graphs, graph isomorphism, and running time analysis of graph algorithms using various representations. It also covers breadth-first search, depth-first search, and the classification of edges in a depth-first search.

barela
Download Presentation

Assignment 2 Remarking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment 2 Remarking 2 y = 0.0323x - 1.5352x + 47.927 Assignment 2 Marks 2 R = 0.9999 100 90 80 70 60 New Mark 50 40 30 20 10 0 0 20 40 60 80 Old Mark

  2. Section V. Graph Algorithms

  3. A directed graph G = (V, E), where V = {1,2,3,4,5,6} and • E = {(1,2), (2,2), (2,4), (2,5), (4,1), (4,5), (5,4), (6,3)}. • The edge (2,2) is a self-loop. (b) An undirected graph G = (V,E), where V = {1,2,3,4,5,6} and E = {(1,2), (1,5), (2,5), (3,6)}. The vertex 4 is isolated. (c) The subgraph of the graph in part (a) induced by the vertex set {1,2,3,6}. Directed and Undirected Graphs

  4. Graph Isomorphism

  5. Trees

  6. Running time often a function of both |V| and |E|. For convenience, drop the | . | in asymptotic notation, e.g. O(V+E). Running Time of Graph Algorithms

  7. Representations: Undirected Graphs Adjacency List Adjacency Matrix

  8. Representations: Directed Graphs Adjacency List Adjacency Matrix

  9. Idea: send out search ‘wave’ from s. Keep track of progress by colouring vertices: Undiscovered vertices are coloured white Just discovered vertices (on the wavefront) are coloured grey. Previously discovered vertices (behind wavefront) are coloured black. Breadth-First Search

  10. Each vertex assigned finite d value at most once. d values assigned are monotonically increasing over time. Q contains vertices with d values {i, …, i, i+1, …, i+1} Time = O(V+E) Breadth-First Search Algorithm

  11. Loop Invariant

  12. On every step at least one vertex turns black. Progress?

  13. There are no gray nodes. All the black nodes form a connected component in G: WHY? For all the black nodes u, d[u] holds the distance from s to u. Termination + LI  Correctness

  14. Example

  15. Example

  16. Example

  17. Example

  18. Example

  19. Example

  20. Example

  21. Example

  22. Example

  23. Recovering shortest path to node

  24. Colours are actually not required

  25. Idea: Continue searching “deeper” into the graph, until we get stuck. If all the edges leaving v have been explored we “backtrack” to the vertex from which v was discovered. Depth First Search (DFS)

  26. Explore every edge, starting from different vertices if necessary. As soon as vertex discovered, explore from it. Keep track of progress by colouring vertices: White: undiscovered vertices Grey: discovered, but not finished (still exploring from it) Black: finished (found everything reachable from it). Depth-First Search

  27. Depth-First Search Algorithm

  28. Example

  29. Example

  30. Example

  31. Example

  32. Example

  33. Example

  34. Example

  35. Example

  36. Example

  37. Example

  38. Example

  39. Example

  40. Example

  41. Example

  42. Example

  43. Example

  44. For any two vertices u and v, exactly one of the following holds: the intervals [d[u], f[u]] and [d[v], f[v]] are disjoint, and neither u nor v is a descendant of the other. the interval [d[u], f[u]] is contained entirely within the interval [d[v], f[v]], and u is a descendant of v. the interval [d[v], f[v]] is contained entirely within the interval [d[u], f[u]], and v is a descendant of u. The Parenthesis Theorem

  45. Vertex v is a proper descendant of vertex u in the depth-first forest if and only if d[u] < d[v] < f[v] < f[u] Corollary

  46. Example

  47. There are four edge types: Tree edges are edges in the depth-first forest Gπ. Edge (u, v) is a tree edge if v was first discovered by exploring edge (u, v). Back edges are those edges (u, v) connecting a vertex u to an ancestor v in a depth-first tree. Self-loops, which may occur in directed graphs, are considered to be back edges. Forward edges are nontree edges (u, v) connecting a vertex u to a descendant v in a depth-first tree. Cross edges are all other edges. They can go between vertices in the same depth-first tree, as long as one vertex is not an ancestor of the other, or they can go between vertices in different depth-first trees. Classification of Edges in DFS

  48. Example

  49. When the edge e=(u,v) is first explored: If v is white – e is a tree edge. If v is gray – e is a back edge. If v is black – e is a forward or a cross edge. Classification of edges

  50. In a depth-first search of an undirected graph G, every edge of G is either a tree edge or a back edge. For Undirected Graphs

More Related