1 / 40

Agenda

This lecture introduces the basics of graph theory and its applications in computer science. Topics include graph representation, path and cycle, graph types, and graph traversal algorithms.

michaelloya
Download Presentation

Agenda

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. Agenda • Lecture Content: • Introduction to Graph • Path and Cycle • Euler & Hamiltonian Cycle • Exercise

  2. Pengumuman QUIZ 2 Minggu Depan

  3. Introduction to Graph

  4. Road Inspection:Wyoming Highway System

  5. Modelled as A Graph • Vertices: the dots with names • Edges: the lines that connect the vertices • Path from Sheridan to Gillette: Sheridan, Buffalo, Gillette. Graph-Theoretic question Is there a path from vertex Greybull to vertex Greybull that traverses every edge exactly once?

  6. Applications of Graph Theory in Computer Science • Computer network • Operating systems • Encryption • Channel allocation, scheduling • Relational database • Coding and compression • Parallel computation • … etc • Maps the problem to graph, states graph-theoretic problem, solves using: • Well-known solution in graph theory • If no solution exists, use heuritics

  7. Definition A graph (or undirected graph) G consists of a set V of vertices (or nodes) and a set E of edges (or arcs) such that each edge e E is associated with an unordered pair of vertices. If there is a unique edge e associated with the vertices v and w, we write e = (v, w) or e = (w, v) .

  8. Example: Computer Network A network is made up of data centers and communication links between computers. We can represent the location of each data center by a point and each communications link by a line segment.

  9. Definition A directed graph (or digraph) G consists of a set V of vertices (or nodes) and a set E of edges (or arcs) such that each edge e E is associated with an ordered pair of vertices. If there is a unique edge e associated with the ordered paired (v, w) of vertices, we write e = (v, w) which denotes an edge from v to w).

  10. Example: Computer Network Directed graphs: if we assign directions to the edges of a graph. The ordered pair (v, w): said to start at v and end at w.

  11. Definition • An edge e in a graph (undirected or directed) that is associated with the pair of vertices v and w is said to be incident on v and w. Vertices v and w are adjacent vertices, and are said to be incident on e. • If G is a graph (undirected or directed) with vertices V and edges E, we write G = (V, E) • Example using Wyoming Highway System: • G consists of the set: • V = {Gre, She, Wor, Buf, Gil, Sho, Cas, Dou, Lan, Mud} • E = {e1, e2, …, e13}

  12. Definition Parallel edges: both edge e1 and e2 are associated with the vertex pair {v1, v2}. Loop: an edge incident on a single vertex. Isolated vertex: a vertex that is not incident on any edge. Simple graph: a graph with neither loops nor parallel edges. Is the one below a simple graph?

  13. Weighted Graph Weighted graph: a graph with numbers on the edges. The number is called weight of edge. Length of a path: the sum of the weights of the edges in the path. The optimal path: a path of minimum length that visits every vertex exactly one time.

  14. Weighted Graph

  15. Definition: The complete graph on n vertices, denoted Kn, is the simple graph with n vertices in which there is an edge between every pair of distinct vertices. Example: K4

  16. Bipartite Graph A graph G = (V, E) is bipartite if there exists subsets V1 and V2 of V such that V1  V2 = , V1  V2 = V, and each edge in E is incident on one vertex in V1 and one vertex in V2.

  17. Is this a Bipartite Graph?

  18. Complete Bipartite Graph The complete bipartite graph on m and n vertices, denoted Km,n is the simple graph whose vertex set is partitioned into sets V1 with m vertices and V2 with n vertices in which the edge set consists of all edges of the form (v1, v2) with v1  V1 and v2  V2 Example: K2,4

  19. Paths and Cycles

  20. Paths: Illustration Vertices: cities Edges: roads Paths: a trip beginning at some city, passing through several cities, and terminating at some city. Let vo and vn be vertices in a graph and ei is incident on vertices vi-1 and vi. A path from vo to vn : (vo, e1, v1, e2, ……, vn-1, en, vn)

  21. Paths • Definition • Let v0 and vn be vertices in a graph. • A path from v0 to vn of length n is an alternating sequence of n+1 vertices and n edges beginning with vertex v0 and ending with vertex vn, (v0,e1,v1,e2,v2,...,vn-1,en,vn) , in which edge ei is incident on vertices vi-1and vi for i = 1, ..., n. • Example • Find a path of length 4 from vertex 1 to vertex 2 in the following graph:

  22. Example (1, e1, 2, e2, 3, e3, 4, e4, 2) is a path of length 4 from 1 to 2 If there are no parallel edges  (1, 2, 3, 4, 2) Is (6) a path? Yes, it is a path of length 0 from 6 to 6 “path” allows repetitions of vertices or edges or both.

  23. Paths and Connected Graph • Note • In the absence of parallel edges, in denoting a path we may suppress the edges. • Previous example: (1,2,3,4,2) • Definition • A graph G is connected if given any vertices v and w in G, there is a path from v to w. • Examples • Are the following graphs connected?

  24. Connected Graph?

  25. Subgraph • Definition • Let G = (V,E) be a graph. • We call (V’,E’) a subgraph of G if (a) V’ V and E’ E. (b) For every edge e’ E’, if e’ is incident on v’ and w’, then v’, w’  V’. • Examples • Is the graph G’ = (V’,E’) a subgraph of the graph G = (V,E)

  26. Subgraph: Example • Find all subgraphshaving at least one vertex of the following graph. v2 e1 v1

  27. Component • Definition • Let G be a graph and let v be a vertex in G. • The subgraph G’ of G consisting of all edges and vertices in G that are contained in some path beginning at v is called the component of G containing v. • Examples • Find the components of this graph which contains • v3 • v4 • v5

  28. Simple Paths and Cycles • Definition • Let v and w be vertices in a graph G. • A simple path from v to w is a path from v to w with no repeated vertices. • A cycle(or circuit) is a path of nonzero length from v to v with no repeated edges. • A simple cycle is a cycle from v to v in which, except for the beginning and ending vertices that are both equal to v, there are no repeated vertices.

  29. Paths and Cycles: Example

  30. Euler Cycles A cycle in a graph G that includes all of the edges and all of the vertices of G. (v6, v4, v7, v5, v1, v3, v4, v1, v2, v5, v4, v2, v3, v6) If a graph G has an Euler cycle, then G is connected and every vertex has even degree. The degree of a vertex v = d(v) is the number of edges incident on v

  31. Konisberg Bridge Problem

  32. Paths and Cycles • Theorem • If a graph G has an Euler cycle, then G is connected and every vertex has even degree. • Theorem • If G is a connected graph and every vertex has even degree, then G has an Euler cycle.

  33. Paths and Cycles • Theorem • If G is a graph with m edges and vertices {v1, v2, ..., vn}, then Σind(vi) = 2m. In particular, the sum of the degrees of all the vertices in a graph is even. • Corollary • In any graph, there are an even number of vertices of odd degree. • Theorem • A graph has a path with no repeated edges from v to w (v≠ w) containing all the edges and vertices if and only if it is connected and v and w are the only vertices having odd degree.

  34. Hamiltonian Cycle & Travelling Salesman Problem

  35. Hamiltonian Cycle • Hamiltonian cycle • A cycle in a graph G that contains each vertex in G exactly once, except for the starting and ending vertex that appears twice. • Examples • Determine if the following graphs have a Hamiltonian cycle.

  36. Examples

  37. Euler vs Hamiltonian Cycle An Euler Cycle visits each edge once. A Hamiltonian Cycle visits each vertex once. Hamiltonian cycle: (a, b, c, d, e, f, g, a) Euler cycle?

  38. Graph with No Hamiltonian Cycle Why? There are 5 vertices, Hamiltonian cycle must have 5 edges, and each vertex has degree 2 Try to eliminate edges. Can you still have 5 edges?

  39. Travelling Salesperson Problem Find a shortest route in which the salesperson can visit each city one time, starting and ending at the same city. Solution: Given a weighted graph G, find a minimum-length Hamilton cycle in G.

  40. Travelling Salesperson Problem: Example List cycles, and pick the one with the shortest length .. Delete edge with high cost, we get: Cmin = (a, b, c, d, a)  length = 2+3+3+2=10

More Related