COSC 2007 Data Structures II Chapter 14 Graphs I.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Discrete Mathematics University of Jazeera College of Information Technology & Design Khulood Ghazal Connectivity Lecture _13.
Analysis of Algorithms CS 477/677
Lecture 5 Graph Theory. Graphs Graphs are the most useful model with computer science such as logical design, formal languages, communication network,
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Review Binary Search Trees Operations on Binary Search Tree
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Graphs Chapter 30 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Applied Discrete Mathematics Week 12: Trees
CS 206 Introduction to Computer Science II 10 / 31 / 2008 Happy Halloween!!! Instructor: Michael Eckmann.
Introduction to Graphs
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
1 Graph Introduction Definitions. 2 Definitions I zDirected Graph (or Di-Graph) is an ordered pair G=(V,E) such that yV is a finite, non-empty set (of.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 09 / 2009 Instructor: Michael Eckmann.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
The Mathematics of Networks Chapter 7. Trees A tree is a graph that –Is connected –Has no circuits Tree.
Chapter 9: Graphs Basic Concepts
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
Lecture 13 Graphs. Introduction to Graphs Examples of Graphs – Airline Route Map What is the fastest way to get from Pittsburgh to St Louis? What is the.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
Chapter 2 Graph Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Graphs Chapter 12.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Vertices and Edges Introduction to Graphs and Networks Mills College Spring 2012.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
GRAPHS THEROY. 2 –Graphs Graph basics and definitions Vertices/nodes, edges, adjacency, incidence Degree, in-degree, out-degree Subgraphs, unions, isomorphism.
Discrete Structures Trees (Ch. 11)
Chapter 5 Graphs  the puzzle of the seven bridge in the Königsberg,  on the Pregel.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Homework #5 Due: October 31, 2000 Christine Kang Graph Concepts and Algorithms.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Graphs Upon completion you will be able to:
Graphs. Contents Terminology Graphs as ADTs Applications of Graphs.
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Graph Concepts Elif Tosun 252a-aa (All graphics created by using demo/graphwin/gw*)
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Chapter 05 Introduction to Graph And Search Algorithms.
Graphs and Shortest Paths Using ADTs and generic programming.
Graph Terms By Susan Ott. Vertices Here are 7 vertices without any edges Each Vertex is labeled a different color and number.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
Basic Concepts Graphs For more notes and topics visit:
Graph Theory.
Graphs Chapter 13.
Graphs All tree structures are hierarchical. This means that each node can only have one parent node. Trees can be used to store data which has a definite.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Chapter 9: Graphs Basic Concepts
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Graphs G = (V, E) V are the vertices; E are the edges.
Elementary Graph Algorithms
Chapter 9: Graphs Basic Concepts
GRAPHS.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

COSC 2007 Data Structures II Chapter 14 Graphs I

2 Topics Introduction & Terminology ADT Graph

3 Introduction Graphs Important mathematical concept that have significant application in computer science Can be viewed as a data structure or ADT Provide a way to represent relationships between data Questions Answered by Using Graphs: Airline flight scheduling: What is the shortest distance between two cities?

4 A graph G is a pair (V, E) where V is a set of vertices (nodes) V = {A, B, C, D, E, F} E is a set of edges (connect vertex) E = {(A,B), (A,D), (B,C),(C,D), (C,E), (D,E)} A B C F D E Terminology and Notations

5 If edge pairs are ordered, the graph is directed, otherwise undirected. We draw edges in undirected graphs with lines with no arrow heads. This is an undirected graph. (B, C) and (C, B) mean the same edge A B C F D E Terminology and Notations

6 If edge pairs are ordered, the graph is directed, otherwise undirected. We draw edges in directed graphs with lines with arrow heads. A B C F D E This is a directed graph. This edge is (B, C). (C, B) would mean a directed edge from C to B Terminology and Notations

7 Directed Graph (Digraph): If an edge between two nodes has a direction (directed edges) Out-degree (OD) of a Node in a Digraph: The number of edges exiting from the node In-degree (ID) of a Node in a Digraph: The number of edges entering the node A B C F D E This is a directed graph. Terminology and Notations

8 Vertex w is adjacent to v if and only if (v, w)  E. In a directed graph the order matters: B is adjacent to A in this graph, but A is not adjacent to B. A B C F D E Terminology and Notations

9 Vertex w is adjacent to v if and only if (v, w)  E. In an undirected graph the order does not matter: we say B is adjacent to A and that A is adjacent to B. A B C F D E Terminology and Notations

10 In some cases each edge has a weight (or cost) associated with it. The costs might be determined by a cost function E.g., c(A, B) = 3, c(D,E) = – 2.3, etc. 4 A B C F D E – Terminology and Notations

11 In some cases each edge has a weight (or cost) associated with it. When no edge exists between two vertices, we say the cost is infinite. E.g., c(C,F) =  A B C F D E – Terminology and Notations

12 Let G = (V, E) be a graph. A subgraph of G is a graph H = (V*, E*) such that V*  V and E*  E. A B C F D E E.g., V* = {A, C, D}, E* = {(C, D)}. Terminology and Notations

13 Let G = (V, E) be a graph. A subgraph of G is a graph H = (V*, E*) such that V*  V and E*  E. A C D E.g., V* = {A, C, D}, E* = {(C, D)}. Terminology and Notations

14 Let G = (V, E) be a graph. A path in the graph is a sequence of vertices w, w,..., w such that (w, w )  E for 1<= i <= N–1. 12Ni i+1 A B C F D E E.g., A, B, C, E is a path in this graph Terminology and Notations

15 Let w, w,..., w be a path. The length of the path is the number of edges, N–1, one less than the number of vertices in the path. A B C F D E E.g., the length of path A, B, C, E is 3. 12N Terminology and Notations

16 Let w, w,..., w be a path in a directed graph. Since each edge (w, w ) in the path is ordered, the arrows on the path are always directed along the path. A B C F D E 12N ii+1 E.g., A, B, C, E is a path in this directed graph, but... Terminology and Notations... but A, B, C, D is not a path, since (C, D) is not an edge.

17 A path is simple if all vertices in it are distinct, except that the first and last could be the same. A B C F D E E.g., the path A, B, C, E is simple... Terminology and Notations... and so is the path A, B, C, E, D, A.

18 If G is an undirected graph, we say it is connected if there is a PATH from every vertex to every other vertex. A B C F D E This undirected graph is not connected. Terminology and Notations

19 If G is an directed graph, we say it is strongly connected if there is a path from every vertex to every other vertex. This directed graph is strongly connected. A B C F D E Terminology and Notations

20 If G is an directed graph, we say it is strongly connected if there is a path from every vertex to every other vertex. This directed graph is not strongly connected; e.g., there’s no path from D to A. A B C F D E Terminology and Notations

21 If G is directed and not strongly connected, but the underlying graph (without direction to the edges) is connected, we say that G is weakly connected. This directed graph is not strongly connected, but it is weakly connected, since... A B C F D E Terminology and Notations

22 If G is directed and not strongly connected, but the underlying graph (without direction to the edges) is connected, we say that G is weakly connected.... since the underlying undirected graph is connected. A B C F D E Terminology and Notations

23 Cycle: a path that begins and ends at the same node but doesn't pass through other nodes more than once A B C F D E The path A, B, C, E, D, A is a cycle. Terminology and Notations

24 A graph with no cycles is called acyclic. A B C F D E This graph is acyclic. Terminology and Notations

25 A graph with no cycles is called acyclic. This directed graph is not acyclic,... A B C F D E Terminology and Notations

26 A graph with no cycles is called acyclic.... but this one is. A Directed Acyclic Graph is often called simply a DAG. A B C F D E Terminology and Notations

27 A complete graph is one that has an edge between every pair of vertices. A B C D E Incomplete: Terminology and Notations

28 A complete graph is one that has an edge between every pair of vertices. ( if the graph contains the maximum possible number of edges) A complete graph is also connected, but the converse is not true Complete: A B C D E Terminology and Notations

29 A complete graph is one that has an edge between every pair of vertices. Suppose G = (V, E) is complete. Can you express |E| as a function of |V|? Complete: A B C D E This graph has |V| = 5 vertices and |E| = 10 edges. Terminology and Notations

30 A free tree is a connected, acyclic, undirected graph. “Free” refers to the fact that there is no vertex designated as the “root.” A B C D E F Terminology and Notations This is a free tree.

31 A free tree is a connected, acyclic, undirected graph. If some vertex is designated as the root, we have a rooted tree. A B C D E F root Terminology and Notations

32 If an undirected graph is acyclic but possibly disconnected, it is a forest. A B C D E F G H I J L K This is a forest. It contains three free trees. Terminology and Notations

33 If an undirected graph is acyclic but possibly disconnected, it is a forest. This graph contains a cycle. Therefore it is neither a free tree nor a forest. A B C D E F G H I J L K Terminology and Notations

34 Review In a graph, a vertex is also known as a(n) ______. node edge path cycle

35 Review A graph consists of ______ sets. two three four five

36 Review A subset of a graph’s vertices and edges is known as a ______. bar graph line graph Subgraph circuit

37 Review Two vertices that are joined by an edge are said to be ______ each other. related to bordering utilizing adjacent to

38 Review All ______ begin and end at the same vertex and do not pass through any other vertices more than once. paths simple paths cycles simple cycles

39 Review Which of the following is true about a simple cycle? it can pass through a vertex more than once it can not pass through a vertex more than once it begins at one vertex and ends at another it passes through only one vertex

40 Review A graph is ______ if each pair of distinct vertices has a path between them. complete disconnected connected full

41 Review A complete graph has a(n) ______ between each pair of distinct vertices. edge path Cycle circuit

42 Review The ______ of a weighted graph have numeric labels. vertices edges paths cycles

43 Review The edges in a ______ indicate a direction. graph multigraph digraph spanning tree

44 Review If there is a directed edge from vertex x to vertex y, which of the following can be concluded about x and y? y is a predecessor of x x is a successor of y x is adjacent to y y is adjacent to x