1/24 Introduction to Graphs. 2/24 Graph Definition Graph : consists of vertices and edges. Each edge must start and end at a vertex. Graph G = (V, E)

Slides:



Advertisements
Similar presentations
Connectivity - Menger’s Theorem Graphs & Algorithms Lecture 3.
Advertisements

Introduction to Algorithms 6.046J/18.401J L ECTURE 16 Greedy Algorithms (and Graphs) Graph representation Minimum spanning trees Optimal substructure Greedy.
Comp 122, Fall 2004 Elementary Graph Algorithms. graphs Lin / Devi Comp 122, Fall 2004 Graphs  Graph G = (V, E) »V = set of vertices »E = set of.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Complexity 16-1 Complexity Andrei Bulatov Non-Approximability.
1 Section 8.2 Graph Terminology. 2 Terms related to undirected graphs Adjacent: 2 vertices u & v in an undirected graph G are adjacent (neighbors) in.
NP-Complete Problems Reading Material: Chapter 10 Sections 1, 2, 3, and 4 only.
Discrete Structures Chapter 7A Graphs Nurul Amelina Nasharuddin Multimedia Department.
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.
Applied Discrete Mathematics Week 12: Trees
Approximation Algorithms Motivation and Definitions TSP Vertex Cover Scheduling.
Let us switch to a new topic:
9.2 Graph Terminology and Special Types Graphs
Graphs Algorithm Design and Analysis Week 4 Bibliography: [CLRS]- Subchap 22.1 – Representation of Graphs.
GRAPH Learning Outcomes Students should be able to:
Graphs Chapter 10.
CS 3343: Analysis of Algorithms Lecture 21: 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,
Sept Elementary Graph Algorithms Graph representation Graph traversal -Breadth-first search -Depth-first search Parenthesis theorem.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
1 Graphs Chapters 9.1 and 9.2 University of Maryland Chapters 9.1 and 9.2 Based on slides by Y. Peng University of Maryland.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 9 (Part 2): Graphs  Graph Terminology (9.2)
1 CS104 : Discrete Structures Chapter V Graph Theory.
9.1 Introduction to Graphs
 Rooted tree and binary tree  Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices.
Data Structures & Algorithms Graphs
Chapter 5 Graphs  the puzzle of the seven bridge in the Königsberg,  on the Pregel.
Graph Theory and Applications
Lecture 10: Graph-Path-Circuit
Introduction to Graphs And Breadth First Search. Graphs: what are they? Representations of pairwise relationships Collections of objects under some specified.
Graphs 9.1 Graphs and Graph Models أ. زينب آل كاظم 1.
Introduction to Graph Theory
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,
Graph. 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.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Shahed University Dr. Shahriar Bijani May  A path is a sequence of vertices P = (v 0, v 1, …, v k ) such that, for 1 ≤ i ≤ k, edge (v i – 1, v.
Chapter 9: Graphs.
Introduction to Graph Theory By: Arun Kumar (Asst. Professor) (Asst. Professor)
Graph Theory Graph Theory - History Leonhard Euler's paper on “Seven Bridges of Königsberg”, published in 1736.
Introduction to NP Instructor: Neelima Gupta 1.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
5.6 Prefix codes and optimal tree Definition 31: Codes with this property which the bit string for a letter never occurs as the first part of the bit string.
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:
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
1 Graphs Chapters 10.1 and 10.2 University of Maryland Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
ICS 353: Design and Analysis of Algorithms NP-Complete Problems King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Elementary Graph Algorithms
Applied Discrete Mathematics Week 13: Graphs
Basic Concepts Graphs For more notes and topics visit:
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
Graphs Rosen, Chapter 8.
CS 3343: Analysis of Algorithms
Graphs Chapters 10.1 and 10.2 Based on slides by Y. Peng University of Maryland.
Computability and Complexity
CS200: Algorithm Analysis
Elementary Graph Algorithms
ICS 353: Design and Analysis of Algorithms
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.
Chapters 8.1 and 8.2 Based on slides by Y. Peng University of Maryland
Problem Solving 4.
Let us switch to a new topic:
Graphs By Rajanikanth B.
Graphs G = (V, E) V are the vertices; E are the edges.
Introduction to Algorithms: Greedy Algorithms (and Graphs)
Presentation transcript:

1/24 Introduction to Graphs

2/24 Graph Definition Graph : consists of vertices and edges. Each edge must start and end at a vertex. Graph G = (V, E) –V = set of vertices –E = set of edges  (V  V) Example:

3/24 Graph Definition Degree of a vertex : number of edges connected to it Example: V 4 has degree = 3 V2V2 V5V5 V3V3 V4V4 V1V1

4/24 Graph Definition Total degree of a graph : sum of the degrees of all the vertices. Note: If a graph has n edges, the total degree = 2n. Example: graph has total degree = 10 V2V2 V3V3 V4V4 V1V1

5/24 Graph Definition The Handshaking Theorem: –Let G = (V, E). Then –Proof: Each edge contributes twice to the degree count of all vertices. –Example: If a graph has 5 vertices, can each vertex have degree 3? Or 4? –The sum is 5  3 = 15 which is an odd number. Not possible. –The sum is 5  4 = 20 = 2 |E| and 20/2 = 10 edges. May be possible.

6/24 Graph Definition Types of graphs –Undirected: edge (u, v) = (v, u); for all v, »(v, v)  E (usually no self loops) »Some may have self loops. –Directed: (u, v) is edge from u to v, denoted as u  v. Self loops are allowed. Is a graph where an edge represents a one-way relation only. –Cf. undirected graph – an edge represents two-way or symmetric relationship between two vertices. The number of directed edges which initiate from vertex v is called the outdegree of v or outdeg(v). The number of directed edges which terminate at vertex v is called the indegree of v or indeg(v).

7/24 Representation of Graphs Two standard ways –Adjacency Lists. –Adjacency Matrix. a dc b a b c d b a d dc c ab ac a dc b

8/24 Adjacency Lists Consists of an array Adj of |V| lists. One list per vertex. For u  V, Adj[u] consists of all vertices adjacent to u. a dc b a b c d b c d dc a dc b a b c d b a d dc c ab ac If weighted, also store weights in adjacency lists.

9/24 Storage Requirement For directed graphs: –Sum of lengths of all adj. lists is  out-degree(v) = |E| v  V –Total storage:  (|V|+|E|) For undirected graphs: –Sum of lengths of all adj. lists is  degree(v) = 2|E| v  V –Total storage:  (|V|+|E|) No. of edges leaving v No. of edges incident on v. Edge (u,v) is incident on vertices u and v.

10/24 Pros and Cons: adj list Pros –Space-efficient, when a graph is sparse. –Can be modified to support many graph variants. Cons –Determining if an edge (u,v)  G is not efficient. Have to search in u ’ s adjacency list.  (degree(u)) time.  (V) in the worst case.

11/24 Adjacency Matrix |V|  |V| matrix A. Number vertices from 1 to |V| in some arbitrary manner. A is then given by: a dc b a dc b A = A T for undirected graphs. If weighted, store weights also in adjacency matrix.

12/24 Space and Time Space:  (|V| 2 ). –Not memory efficient for large graphs. Time: to list all vertices adjacent to u:  (|V|). Time: to determine if (u, v)  E:  (1). Can store weights instead of bits for weighted graph.

13/24 Directed Graphs –Theorem –Examples (continued): Adjacency matrix of a directed graph: –outdeg(V 1 ) = 1, indeg(V 1 ) = 2 –outdeg(V 2 ) = 2, indeg(V 2 ) = 1 –outdeg(V 3 ) = 0, indeg(V 3 ) = 2 –outdeg(V 4 ) = 2, indeg(V 4 ) = 0

14/24 Each edge e has a weight, wt(e) graph may be undirected or directed weight may represent length, cost, capacity, etc adjacency matrix becomes weight matrix adjacency lists include weight in node v w y x z a weighted graph G Weighted Graphs

15/24 Vertex cover A set of vertices that cover all edges, i.e., at least one vertex of all edges is in the set. I.e., set of vertices W  V with for all {x,y}  E: x  W or y  W. Vertex Cover problem: –Given G, find vertex cover of minimum size Modified from

16/24 Subset S of vertices such that no two vertices in S are connected Independent Set (I)

17/24 Subset S of vertices such that no two vertices in S are connected Independent Set (II)

18/24 INSTANCE: graph G SOLUTION: independent set S in G MEASURE: maximize the size of S INSTANCE: graph G, number K QUESTION: does G have independent set of size  K OPTIMIZATION VERSION: DECISION VERSION: Independent Set (III)

19/24 Subset S of vertices such that every two vertices in S are connected Clique (I)

20/24 Clique INSTANCE: graph G, number K QUESTION: does G have a clique of size  K? Clique (II)

21/24 Relations The following are equivalent –G has an independent set with at least k vertices –The complement of G has a clique with at least k vertices –G has a vertex cover with at most n-k vertices

22/24 Bipartite Graphs A bipartite graph G is –a graph in which the vertices V can be partitioned into two disjoint subsets V 1 and V 2 such that no two vertices in V 1 are adjacent; no two vertices in V 2 are adjacent. A complete bipartite graph K m,n is –Is a bipartite graph in which the sets V 1 and V 2 contain m and n vertices, respectively, and every vertex in V 1 is adjacent to every vertex in V 2. –Q: How many edges ?

23/24 Assignment Problem Assignment problem. –Input: weighted, complete bipartite graph G = (L  R, E) with |L| = |R|. –Goal: find a perfect matching of min weight '2'3'4'5' Min cost perfect matching M = { 1-2', 2-3', 3-5', 4-1', 5-4' } cost(M) = = Introduction to Bioinformatics Algorithms

24/24 Assignment problem and related problems L: n jobs, R: m machines, weight of an edge (i,j) in E: time for job i taken on machine j. –Assign n jobs to each of m machines such that the total processing time is minimized. Matching: is a subset of E such that no two edges in the subset are adjacent. –Perfect matching: A matching saturates all vertices. –Maximum matching: A matching with the largest possible number of edges. Min-cost maximum matching problem: Find a max matching in a graph (with edge weights) such that the total edge weight is minimized.