Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R5. Graphs.

Slides:



Advertisements
Similar presentations
Chapter 9 Graphs.
Advertisements

22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
22C:19 Discrete Math Graphs Fall 2014 Sukumar Ghosh.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
Graph.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Chapter 9: Graphs Basic Concepts
22C:19 Discrete Math Graphs Spring 2014 Sukumar Ghosh.
Social Media Mining Graph Essentials.
Graph. Data Structures Linear data structures: –Array, linked list, stack, queue Non linear data structures: –Tree, binary tree, graph and digraph.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
1 Abstract Data Type We have discussed: List Tree Today we will talk about Graph.
Been-Chian Chien, Wei-Pang Yang, and Wen-Yang Lin 6-1 Chapter 6 Graphs Introduction to Data Structure CHAPTER 6 GRAPHS 6.1 The Graph Abstract Data Type.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
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.
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.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Representing and Using Graphs
Graphs Rosen, Chapter 8. Isomorphism (Rosen 560 to 563) Are two graphs G1 and G2 of equal form? That is, could I rename the vertices of G1 such that the.
Data Structures Week 9 Introduction to Graphs Consider the following problem. A river with an island and bridges. The problem is to see if there is a way.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Mathematics of Networks (Cont)
Data Structures & Algorithms Graphs
Chapter 5 Graphs  the puzzle of the seven bridge in the Königsberg,  on the Pregel.
CISC 235: Topic 9 Introduction to Graphs. CISC 235 Topic 92 Outline Graph Definition Terminology Representations Traversals.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 10. Graphs.
Graph Theory and Applications
Introduction to Graph Theory
Mudasser Naseer 1 1/9/2016 CS 201: Design and Analysis of Algorithms Lecture # 17 Elementary Graph Algorithms (CH # 22)
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graphs 황승원 Fall 2010 CSE, POSTECH. 2 2 Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Chapter 05 Introduction to Graph And Search Algorithms.
Graph Theory Graph Theory - History Leonhard Euler's paper on “Seven Bridges of Königsberg”, published in 1736.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 10. Graphs.
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.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
BCA-II Data Structure Using C Submitted By: Veenu Saini
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
CSCE 210 Data Structures and Algorithms
CS 201: Design and Analysis of Algorithms
Graphs Rosen, Chapter 8.
Graph theory Definitions Trees, cycles, directed graphs.
Depth-First Search.
CS120 Graphs.
Discrete Maths 9. Graphs Objective
Graph Algorithm.
Graphs Chapter 13.
Graphs Chapter 15 explain graph-based algorithms Graph definitions
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.
Chapter 9: Graphs Basic Concepts
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Graph Operations And Representation
Chapter 9: Graphs Basic Concepts
Chapter 9 Graph algorithms
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R5. Graphs

Prof. Amr Goneid, AUC2 Graphs

3 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Spanning Trees

Prof. Amr Goneid, AUC4 1. Basic Definitions A graph G (V,E) can be defined as a pair (V,E), where V is a set of vertices, and E is a set of edges between the vertices E = {(u,v) | u, v  V}. e.g. V = {A,B,C,D,E,F,G} E = {( A,B),(A,F),(B,C),(C,G),(D,E),(D,G),(E,F),(F,G)} If no weights are associated with the edges, an edge is either present(“1”) or absent (“0”). A F GB E DC

Prof. Amr Goneid, AUC5 Basic Definitions A graph is like a road map. Cities are vertices. Roads from city to city are edges. You could consider junctions to be vertices, too. If you don't want to count them as vertices, a road may connect more than two cities. So strictly speaking you have hyperedges in a hypergraph. If you want to allow more than one road between each pair of cities, you have a multigraph, instead.

Prof. Amr Goneid, AUC6 Basic Definitions Adjacency: If vertices u,v have an edge e = (u,v) | u, v  V then u and v are adjacent. A weighted graph has a weight associated with each edge. Undirected Graph is a graph in which the adjacency is symmetric, i.e., e = (u,v) = (v,u) A Sub-Graph: has a subset of the vertices and the edges A F GB E DC

Prof. Amr Goneid, AUC7 Basic Definitions Directed Graph: is a graph in which adjacency is not symmetric, i.e., (u,v)  (v,u) Such graphs are also called “Digraphs” Directed Weighted Graph: A directed graph with a weight for each edge. Also called a network. A F GB E DC

Prof. Amr Goneid, AUC8 2. Paths & Cycles Path: A list of vertices of a graph where each vertex has an edge from it to the next vertex. Simple Path: A path that repeats no vertex. Cycle: A path that starts and ends at the same vertex and includes other vertices at most once. A F GB E DC A F GB E DC

Prof. Amr Goneid, AUC9 Directed Acyclic Graph (DAG) Directed Acyclic Graph (DAG): A directed graph with no path that starts and ends at the same vertex A F GB E DC

Prof. Amr Goneid, AUC10 Hamiltonian Cycle Hamiltonian Cycle: A cycle that includes all other vertices only once, e.g. {D,B,C,G,A,F,E,D} Named after Sir William Rowan Hamilton (1805 –1865) The Knight’s Tour problem is a Hamiltonian cycle problemKnight’s Tour A F GB E DC Icosian Game

Prof. Amr Goneid, AUC11 Hamiltonian Cycle Demo A Hamiltonian Cycle is a cycle that visits each node exactly once. Here we show a Hamiltonian cycle on a 5-dimensional hypercube. It starts by completely traversing the 4-dimensional hypercube on the left before reversing the traversal on the right subcube. Hamiltonian cycles on hypercubes provide constructions for Gray codes: orderings of all subsets of n items such that neighboring subsets differ in exactly one element. Hamilitonian cycle is an NP-complete problem, so no worst-case efficient algorithm exists to find such a cycle. In practice, we can find Hamiltonian cycles in modest-sized graphs by using backtracking with clever pruning to reduce the search space.

Prof. Amr Goneid, AUC12 Hamiltonian Cycle Demo inatorica/animations/ham.html Hamiltonian Cycle Demo

Prof. Amr Goneid, AUC13 Euler Circuit Leonhard Euler Konigsberg Bridges (1736) (not Eulerian) Euler Circuit: A cycle that includes every edge once. Used in bioinformatics to reconstruct the DNA sequence from its fragments

Prof. Amr Goneid, AUC14 Euler Circuit Demo An Euler circuit in a graph is a traversal of all the edges of the graph that visits each edge exactly once before returning home. A graph has an Euler circuit if and only if all its vertices are that of even degrees. It is amusing to watch as the Euler circuit finds a way back home to a seemingly blocked off start vertex. We are allowed (indeed required) to visit vertices multiple times in an Eulerian cycle, but not edges.

Prof. Amr Goneid, AUC15 Euler Circuit Demo atorica/animations/euler.html Euler Circuit Demo

Prof. Amr Goneid, AUC16 3. Connectivity Connected Graph: An undirected graph with a path from every vertex to every other vertex A Disconnected Graph may have several connected components Tree: A connected Acyclic graph A F GB E DC A F GB E DC

Prof. Amr Goneid, AUC17 Connected Components Demo What happens when you start with an empty graph and add random edges between vertices? As you add more and more edges, the number of connected components in the graph can be expected to drop, until finally the graph is connected. An important result from the theory of random graphs states that such graphs very quickly develop a single ``giant'' component which eventually absorbs all the vertices.

Prof. Amr Goneid, AUC18 Connected Components Demo atorica/animations/concomp.html Randomly Connected Graph Demo

Prof. Amr Goneid, AUC19 Connectivity Articulation Vertex: if removed with all of its edges will cause a connected graph to be disconnected, e.g., G and D are articulation vertices A F B E DC A F GB E DC

Prof. Amr Goneid, AUC20 Connectivity Degree Of a vertex, the number of edges connected to it. Degree Of a graph, the maximum degree of any vertex (e.g. B has degree 2, graph has degree 3). In a connected graph the sum of the degrees is twice the number of edges, i.e A F GB E DC

Prof. Amr Goneid, AUC21 Connectivity In-Degree/Out-Degree: the number of edges coming into/emerging from a vertex in a connected graph (e.g. G has in-degree 3 and out-degree 1). A F GB E DC

Prof. Amr Goneid, AUC22 Connectivity Complete Graph: There is an edge between every vertex and every other vertex. In this case, the number of edges is maximum: Notice that the minimum number of edges for a connected graph ( a tree in this case) is (V-1) A D CB

Prof. Amr Goneid, AUC23 Density (of edges) Density of a Graph: Dense Graph: Number of edges is close to E max = V(V-1)/2. So, E =  (V 2 ) and D is close to 1 Sparse Graph: Number of edges is close to E min = (V-1). So, E = O(V)

Prof. Amr Goneid, AUC24 4. Other Properties Planar Graph: A graph that can be drawn in the plain without edges crossing A D CB A D CB Non-Planar

Prof. Amr Goneid, AUC25 Other Properties Graph Coloring: To assign color (or any distinctive mark) to vertices such that no two adjacent vertices have the same color. The minimum number of colors needed is called the Chromatic Order of the graph  (G). For a complete graph,  (G) = V

Prof. Amr Goneid, AUC26 Other Properties An Application: Find the number of exam slots for 5 courses. If a single student attends two courses, an edge exists between them. EE Math CS PhysEcon SlotCourses 1 (red) CS 2 (Green) EE, Econ, Phys 3 (Blue) Math

Prof. Amr Goneid, AUC27 5. Representation Adjacency Matrix: V x V Matrix a(i,j) a(i,j) = 1 if vertices (i) and (j) are adjacent, zero otherwise. Usually self loops are not allowed so that a(i,i) = 0. For undirected graphs, a(i,j) = a(j,i) For weighted graphs, a(i,j) = w ij A D CB ABCD A0110 B1010 C1101 D0010

Prof. Amr Goneid, AUC28 Representation The adjacency matrix is appropriate for dense graphs but not compact for sparse graphs. e.g., for a lattice graph, the degree of a vertex is 4, so that E = 4V. Number of “1’s” to total matrix size is approximately 2 E / V 2 = 8 / V. For V >> 8, the matrix is dominated by zeros.

Prof. Amr Goneid, AUC29 Representation Adjacency List: An array of vertices with pointers to linked lists of adjacent nodes, e.g., The size is O(E + V) so it is compact for sparse graphs. A D CB C B D B A C AC ABD C

Prof. Amr Goneid, AUC30 6. Spanning Trees Consider a connected undirected graph G(V,E). A sub-graph S(V,T) is a spanning tree of the graph (G) if: V(S) = V(G) and T  E S is a tree, i.e., S is connected and has no cycles

Prof. Amr Goneid, AUC31 Spanning Tree S(V,T): V = {A,B,C,D,E,F,G} T = {AB,AF,CD,DE,EF,FG} F E GA D CB

Prof. Amr Goneid, AUC32 Spanning Tree Notice that: |T| = |V| - 1 and adding any edge (u,v)  T will produce a cycle so that S is no longer a spanning tree (e.g. adding (G,D)) F E GA D CB

Prof. Amr Goneid, AUC33 One Graph, Several Spanning Trees

Prof. Amr Goneid, AUC34 For a connected undirected graph G(V,E), a spanning forest is S(V,T) if S has no cycles and T  E. S(V,T) will be composed of trees (V 1,T 1 ), (V 2,T 2 ), …, (V k,T k ), k ≤ |V| F E GA D CB Spanning Forest