Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binhai Zhu Computer Science Department, Montana State University

Similar presentations


Presentation on theme: "Binhai Zhu Computer Science Department, Montana State University"— Presentation transcript:

1 Binhai Zhu Computer Science Department, Montana State University
Graph Algorithms, 1 Binhai Zhu Computer Science Department, Montana State University Frequently, presenters must deliver material of a technical nature to an audience unfamiliar with the topic or vocabulary. The material may be complex or heavy with detail. To present technical material effectively, use the following guidelines from Dale Carnegie Training®. Consider the amount of time available and prepare to organize your material. Narrow your topic. Divide your presentation into clear segments. Follow a logical progression. Maintain your focus throughout. Close the presentation with a summary, repetition of the key steps, or a logical conclusion. Keep your audience in mind at all times. For example, be sure data is clear and information is relevant. Keep the level of detail and vocabulary appropriate for the audience. Use visuals to support key points or steps. Keep alert to the needs of your listeners, and you will have a more receptive audience. 7/1/2019

2 Background In many applications, a tree (the most complex data structure we have learnt so far) is not enough. (1) Think about the network where the vertices are all the Internet routers in the world. (2) Think about the human acquaintance network, say within MSU-Bozeman. 7/1/2019

3 Background In many applications, a tree (the most complex data structure we have learnt so far) is not enough. (1) Think about the network where the vertices are all the Internet routers in the world. (2) Think about the human acquaintance network, say within MSU-Bozeman. (3) Again, sometimes we might need a structure more complex than a single graph. But for most of the applications, a graph should be enough. 7/1/2019

4 Definition An (undirected) graph is a pair <V,E>.
(1) V is the set of vertices, |V|=n. (2) E is the set of edges, |E|=m. 7/1/2019

5 Definition An (undirected) graph is a pair <V,E>.
(1) V is the set of vertices, |V|=n. (2) E is the set of edges, |E|=m. (3) So the size of a graph is |V|+|E|. 7/1/2019

6 Definition An (undirected) graph is a pair <V,E>.
(1) V is the set of vertices, |V|=n. (2) E is the set of edges, |E|=m. (3) So the size of a graph is |V|+|E|. In the graph on our right, n=5, m=6. 7/1/2019

7 Graph Basics,1 In a graph G of n vertices, how many edges could we have? 7/1/2019

8 Graph Basics,1 In a graph G of n vertices, how many edges could we have? Minimum: 0 Maximum: n(n-1)/2, how could that happen? 7/1/2019

9 Graph Basics,1 In a graph G of n vertices, how many edges could we have? Minimum: 0 Maximum: n(n-1)/2, how could that happen? When G is a complete graph! 7/1/2019

10 Graph Basics,2 The degree of a vertex v in G, deg(v), is the number of edges incident to v. deg(v1) = 3,deg(v2)=2 deg(v3)=1,deg(v4)=2 Can you see some pattern? v4 v1 v3 v2 7/1/2019

11 Graph Basics,2 The degree of a vertex v in G, deg(v), is the number of edges incident to v. deg(v1) = 3,deg(v2)=2 deg(v3)=1,deg(v4)=2 ∑v deg(v) is even. v4 v1 v3 v2 7/1/2019

12 Graph Basics,2 The degree of a vertex v in G, deg(v), is the number of edges incident to v. deg(v1) = 3,deg(v2)=2 deg(v3)=1,deg(v4)=2 ∑v deg(v) is even. Why? v4 v1 v3 v2 7/1/2019

13 Graph Basics,3 A path in a graph G is a sequence of vertices in which each successive vertex (starting from the 2nd one) is adjacent to its predecessor in the path. In a simple path, the vertices and edge are distinct. A cycle is a simple path with the same first and final vertex. v1v2v3v4 is not a path. v3v1v2v4v1 is a path, but not a simple path. v3v1v2v4 is a simple path (of length 3). v1v2v4v1 is a cycle. v4 v1 v3 v2 7/1/2019

14 Graph Basics,3 A graph G is connected if any two vertices are connected by some path. A graph which is not connected consists of a set of connect components, which are maximal connected subgraphs. In this graph, we have 2 connected components. Q: What is the maximum number of connected components in any graph? v5 v4 v1 v6 v3 v2 7/1/2019

15 Graph Basics,3 An acyclic connected graph is called a tree. A set of trees is called a forest. A spanning tree of a connected graph G is a subgraph containing all the vertices of G and is itself a tree. Q: What is the number of edges of a tree with n vertices? v5 v4 v1 v6 v3 v2 7/1/2019

16 Graph Basics,3 An acyclic connected graph is called a tree. A set of trees is called a forest. A spanning tree of a connected G is a subgraph containing all the vertices of G and is itself a tree. An example of a spanning tree. v5 v4 v1 v6 v3 v2 7/1/2019

17 Graph Basics,3 An acyclic connected graph is called a tree. A set of trees is called a forest. A spanning tree of a connected G is a subgraph containing all the vertices of G and is itself a tree. An example of a spanning tree. v5 v4 v1 v6 v3 v2 7/1/2019

18 Graph Basics,4 A graph with all possible edges present is called a complete graph. If it has n vertices, we denote as Kn. The complement of a given graph G of n vertices, Gc, is a graph with the same vertices and an edge is in Gc if and only if it is not in G. G U Gc = ? v4 v1 v5 v3 v2 7/1/2019

19 Graph Basics,4 A graph with all possible edges presented is called a complete graph. If it has n vertices, we denote as Kn. The complement of a given graph G of n vertices, Gc, is a graph with the same vertices and an edge is in Gc if and only if it is not in G. G U Gc = Kn v4 v1 v5 v3 v2 GC is in yellow 7/1/2019

20 Graph Representation A graph is a data structure, so we need to consider how to represent it. Idea? v4 v1 v5 v3 v2 7/1/2019

21 Graph Representation A graph is a data structure, so we need to consider how to represent it. Adjacency matrix: aij = 1 if vi is adjacent to vj v4 v1 v5 v3 v2 7/1/2019

22 Graph Representation A graph is a data structure, so we need to consider how to represent it. Adjacency matrix: aij = 1 if vi is adjacent to vj; otherwise it is 0. v4 v1 v2 v3 v4 v5 v1 1 1 1 v1 v2 1 1 v5 v3 v3 1 1 v2 v4 1 1 v5 1 7/1/2019

23 Graph Representation A graph is a data structure, so we need to consider how to represent it. Adjacency matrix: aij = 1 if vi is adjacent to vj; otherwise it is 0. v4 v1 v2 v3 v4 v5 v1 1 1 1 v1 v2 1 1 v5 v3 v3 1 1 v2 v4 1 1 What property does this matrix have? v5 1 7/1/2019

24 Graph Representation A graph is a data structure, so we need to consider how to represent it. Adjacency matrix: aij = 1 if vi is adjacent to vj; otherwise it is 0. v4 v1 v2 v3 v4 v5 v1 1 1 1 v1 v2 1 1 v5 v3 v3 1 1 v2 v4 1 1 What is the cost of this representation? v5 1 7/1/2019

25 Graph Representation A graph is a data structure, so we need to consider how to represent it. Adjacency list: for each vi maintain the list of vertices incident to vi. v4 v1: v4 v2 v3 v1 v2: v5 v3 v3: v1 v5 v2 v4: v5: 7/1/2019

26 Graph Representation A graph is a data structure, so we need to consider how to represent it. Adjacency list: for each vi maintain the list of vertices incident to vi. v4 v1: v4 v2 v3 v1 v2: v5 v3 v3: v1 v5 v2 v4: What is the cost of this representation? v5: 7/1/2019

27 Graph Representation A graph is a data structure, so we need to consider how to represent it. Adjacency list: for each vi maintain the list of vertices incident to vi. v4 v1: v4 v2 v3 v1 v2: v5 v3 v3: v1 v5 v2 v4: What is the cost of this representation? O(|V|+|E|)=O(n+m) v5: 7/1/2019


Download ppt "Binhai Zhu Computer Science Department, Montana State University"

Similar presentations


Ads by Google