1 / 18

Section 13

Section 13. Questions Questions Graphs. Graphs. A graph representation: Adjacency matrix. Pros:? Cons:? Neighbor lists. Pros:? Cons:?. Graphs. A graph representation: Adjacency matrix. Pros: O(1) check if u is a neighbor of v.

gamma
Download Presentation

Section 13

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. Section 13 • Questions • Questions • Graphs

  2. Graphs • A graph representation: • Adjacency matrix. • Pros:? • Cons:? • Neighbor lists. • Pros:? • Cons:?

  3. Graphs • A graph representation: • Adjacency matrix. • Pros: O(1) check if u is a neighbor of v. • Cons:Consumes lots of memory for sparse graphs. Slow in finding all neighbors. • Neighbor lists. • Pros:Consume little memory, easy to find all neighbors. • Cons:Check if u is a neighbor of v can be expensive.

  4. Graphs • In practice, usually neighbor lists are used.

  5. Some graphs we often meet. • Acyclic - no cycles. • Directed, undirected. • Directed, acyclic graph = dag.

  6. Topological sorting • A problem: Given a dag G determine the ordering of the vertices such that v precedes u iff there is an edge (v, u) in G. • Algorithm: Take out the vertice with no incoming edges along with its edges, put in the beginning of a list, repeat while necessary. • Implementation?

  7. Topological sorting • More descriptive description: • 1. For each vertice v compute count[v] - the number of incoming edges. • 2. Put all the vertices with count[v] = 0 to the stack • 3. repeat: Take top element v from the stack, decrease count[u] for its neighbors u.

  8. Topological sorting • Implementation: • 1. Use DFS/BFS to compute count. • 2. Complexity? • O(E + V) - 1. takes E, the loop is executed V times, the number of operations inside loop sums up to E.

  9. Topological sorting • Applications: • Job scheduling.

  10. The bridges of Konigsberg

  11. The bridges of Konigsberg • In 1735 Leonard Euler asked himself a question. • Is it possible to walk around Konigsberg walking through each bridge exactly once?

  12. The brid(g)es of Konigsberg

  13. The bridges of Konigsberg • It’s not possible! • It’s a graph problem!

  14. Euler’s theorem • The Euler circuit passes through each edge in the graph only once and returns to the starting point. • Theorem: The graph has an Euler circuit iff every vertice has even degree. (the number of adjacent vertices)

  15. Euler’s circuit • How to check if there’s one?

  16. Hamiltonian’s circuit • A cycle which passes through vertice only once. • How to find one efficiently?

  17. Hamiltonian’s cycle • Nobody knows!!!

  18. REWARD!!! $1000000 is offered to anyone who finds an efficient algorithm for finding Hamiltonian cycle in a graph. DEAD OR ALIVE

More Related