1 / 22

Graph

Graph. Algorithms Baojian Hua huabj@mail.ustc.edu.cn May 26, 2008. Graph. Graph is a basic and simple mathematical abstraction with a long history Date back at least to Euler Focus on topological structure (geometry?) With many important applications Map, scheduling, transaction, …

pravat
Télécharger la présentation

Graph

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. Graph Algorithms Baojian Hua huabj@mail.ustc.edu.cn May 26, 2008

  2. Graph • Graph is a basic and simple mathematical abstraction with a long history • Date back at least to Euler • Focus on topological structure (geometry?) • With many important applications • Map, scheduling, transaction, … • In computer science: • Network, compiler, web, circuit, …

  3. Representation

  4. name name succs succs next next node next /\ node next Adjacency List // a simplified representation (no explicit edges) class Node { String name; Successors succs; Node next; } class Successors { Node node; Successors next; }

  5. name edges next from to next /\ Or With Edges class Node { String name; Edges edges; Node next; } class Edges { Node from; Node to; Edegs next; }

  6. Depth-first Search (DFS) // a much simplified version dfs (Node n){ visited [n] = true; // memoization :-) for (each successors t of n){ if (visited[t]) {} else dfs (t); } } // with initial call dfs (start).

  7. Example B A D C Initial start node: A

  8. Example B A D C Visited A

  9. Example B A D C Visited B

  10. Example B A D C Visited C

  11. Example B A D C Visited D

  12. Example B A D C All successors of D has been visited. Go back from D.

  13. Example B A D C All successors of C has been visited. Go back from C.

  14. Example B A D C All successors of B has been visited. Go back from B.

  15. Example B A D C All successors of A has been visited. Go back from A.

  16. DFS Tree B A D C

  17. DFS Tree B A D C

  18. DFS Tree B A D C

  19. Problems #1 • Simple Path: is there a simple path from node u to v in a digraph g? • Or is u and v connected?

  20. Problems #2 • Simple connectivity: is a given undirected graph connected? • Or how many nodes are there in a connected component?

  21. Problems #3 • Cycle detection: is there a cycle in a digraph?

  22. Problems #4 • Two colorability: is it possible to color all the nodes in a digraph g such that no adjacent nodes with the same color? • Or: is there a cycle with odd length?

More Related