MCA 202: Discrete Mathematics Instructor Neelima Gupta

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Discrete Mathematics 6. GRAPHS Lecture 10 Dr.-Ing. Erwin Sitompul
1 On c-Vertex Ranking of Graphs Yung-Ling Lai & Yi-Ming Chen National Chiayi University Taiwan.
§5 Minimum Spanning Tree 【 Definition 】 A spanning tree of a graph G is a tree which consists of V( G ) and a subset of E( G ) 〖 Example 〗 A complete.
Instructor: Shengyu Zhang 1. Content Two problems  Minimum Spanning Tree  Huffman encoding One approach: greedy algorithms 2.
CS 253: Algorithms Chapter 22 Graphs Credit: Dr. George Bebis.
Analysis of Algorithms CS 477/677
Instructor Neelima Gupta Table of Contents Approximation Algorithms.
MCA 202: Discrete Mathematics under construction Instructor Neelima Gupta
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
Graph-02.
Review Binary Search Trees Operations on Binary Search Tree
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graphs. Overview What is a graph? Some terminology Types of graph Implementing graphs (briefly) Some graph algorithms Graphs 2/18.
Graphs CS-240/341. Uses for Graphs computer networks and routing airline flights geographic maps course prerequisite structures tasks for completing a.
Introduction to Graphs
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
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.
Chapter 9: Graphs Basic Concepts
Chapter 4 Graphs.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
GRAPH Learning Outcomes Students should be able to:
Graph. Data Structures Linear data structures: –Array, linked list, stack, queue Non linear data structures: –Tree, binary tree, graph and digraph.
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
7.1 and 7.2: Spanning Trees. A network is a graph that is connected –The network must be a sub-graph of the original graph (its edges must come from the.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 20.
1 CS104 : Discrete Structures Chapter V Graph Theory.
CS 200 Algorithms and Data Structures
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Data Structures & Algorithms Graphs
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.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Graphs Upon completion you will be able to:
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.
1) Find and label the degree of each vertex in the graph.
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.
Introduction to NP Instructor: Neelima Gupta 1.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University Graphs Original Slides by Rada Mihalcea.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Programming Abstractions Cynthia Lee CS106B. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
Graphs.
Graphs Chapter 20.
Introduction to Graphs
Introduction to Graphs
CS120 Graphs.
Discrete Maths 9. Graphs Objective
Refresh and Get Ready for More
Spanning Trees Discrete Mathematics.
Connected Components Minimum Spanning Tree
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.
Minimum Spanning Trees
Chapter 9: Graphs Basic Concepts
Graph Operations And Representation
Graph Theory By Amy C. and John M..
Graphs G = (V, E) V are the vertices; E are the edges.
Graphs CS 2606.
Chapter 9: Graphs Basic Concepts
Graphs G = (V,E) V is the vertex set.
GRAPHS.
Introduction to Graphs
Presentation transcript:

MCA 202: Discrete Mathematics Instructor Neelima Gupta

Introduction to Graphs Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Map of Highways connecting Cities v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) Two way Highways ---  Undirected Graph

Map of One Way Highways connecting Cities v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) One way Highways ---  Directed Graph

Some of the Qs we often want to answer Is there a path from city ‘a’ to city ‘b’? Is there a path to ‘c’ from ‘a’ via ’b’? How can I visit all the cities and come back to my original city without traveling any sector twice. (Euler Tour) Can I visit all the cities and come back to my original city without traveling any city twice? (Hamiltonian Circuit) Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Map of Highways with cost of traveling v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Qs we may want to answer What is the cheapest path from city ‘a’ to city ‘b’? (Shortest Path Problem) Can I visit all the cities and come back to my original city without traveling any city twice? Can I get the cheapest such tour? (Traveling Salesman Problem) Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Connecting the Cities in a Cheapest Way (Minimum Spanning Tree) v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Form a network of Computers in a cheapest way (MST) Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Graph A graph is a data structure to capture pairwise relationships amongst the objects. It is a collection of vertices and edges. In the example of “map of highways connecting cities”, cities can be represented by vertices and highways are binary relationships between cities which can be represented by edges. Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Directed Graphs V={v 1, v 2,…} E ⊂ V x V E: V V E ⊆ {(u, v): u, v ∈ V } E is a set of ordered pairs (u,v) of vertices from V representing an edge from u to v. v is stb the head of the arrow and u the tail. Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Map of One Way Highways connecting Cities v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) One way Highways ---  Directed Graph

Undirected Graphs V={v 1, v 2,…} E is a collection of subsets of V of size 2. However, with a slight abuse of notation we’ll continue to write (u,v) for an undirected edge instead of {u,v} and whether (u,v) is an ordered pair or not will be clear from the context. To capture self-loops, subsets are allowed to be multisets. The edge (u, v) is stb incident on u and v. u and v are stb adjacent to each other. Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Map of Highways connecting Cities v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) Two way Highways ---  Undirected Graph

Representation of Graphs Thanks, Neeharika Chaudhary,Roll No.:26(MCA 2012)

2D Array Representation G=(V,E) v 1 v 2 ………………. v n v 1 v 2. v n G(Vi,Vj)=1 iff (Vi,Vj) Є E(G) Thanks, Neeharika Chaudhary,Roll No.:26(MCA 2012)

Undirected Graph v 2 v 1 v 6 v 4 v 3 v 5 MATRIX IS SYMMETRIC FOR AN UNDIRECTED GRAPH Thanks, Neeharika Chaudhary,Roll No.:26(MCA 2012) v 1 v 2 v 3 v 4 v 5 v v1v2v3v4v5v6v1v2v3v4v5v6

Directed Graph v 2 v 1 v 6 v 4 v 3 v 5 MATRIX IS NOT SYMMETRIC FOR A DIRECTED GRAPH Thanks, Neeharika Chaudhary,Roll No.:26(MCA 2012) v 1 v 2 v 3 v 4 v 5 v 6 v1v2v3v4v5v6v1v2v3v4v5v

Weighted Graphs V={v 1, v 2,…} W: E R Weights could be – cost of traveling – cost of connecting cities – cost of connecting computers Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Thanks Neeraj Roll no-28(MCA 2012) Adjacency List Representation

Thanks Neeraj Roll no-28(MCA 2012) For Undirected graphs v1 v2 v3 v4 v5 v6 v2 v1 v2 v4v6 v3 v4 v3 v6 v4 Size =2 X No. of Edges =2|E|

Thanks Neeraj Roll no-28(MCA 2012) Size of Adjacency Matrix is theta (v 2 ). We know that |E| < O (v 2 ). How? When E<< v 2 /2 i.e. when the graph is sparse, then adjacency list representtaion saves a lot of space.

Thanks Neeraj Roll no-28(MCA 2012) v1 v2 v3 v4 v5 v6 v2 v1 v2 v4v6 v3 v4 v3 v6 v4 For Directed Graphs Χ Size =|E| ∑ in deg(v)= ∑ out deg(v)= |E|

Map of Highways with cost of traveling v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Multi - Graphs A graph in which there could be multiple edges between a pair of vertices. For directed graph, a multi-graph would be the one allowing multiple edges from a vertex u to another vertex v. Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Map of Highways with more than one way to reach directly May be more than one highway. One or more roadway, one or more railway, one or more airway: each may have different cost in general Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Map of Highways connecting Cities v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Two way Highways ---  Undirected Multi-Graph

Map of Highways connecting Cities v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Two way Highways ---  Undirected Multi-Graph

Paths and Circuits Paths v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22, Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of edges

Paths and Circuits Paths v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of edges

Paths and Circuits Paths v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of edges

Paths and Circuits Paths v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22, Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of edges

Paths and Circuits Circuits v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of edges

Paths and Circuits Circuits v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of edges

Paths and Circuits Circuits v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of edges

Paths and Circuits in a Directed Graph Paths v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of directed edges

Paths and Circuits in a Directed Graph Paths v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of directed edges

Paths and Circuits in a Directed Graph Paths v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of directed edges

Paths and Circuits in a Directed Graph Circuits v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of directed edges

Paths and Circuits in a Directed Graph Circuits v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of directed edges

Paths and Circuits in a Directed Graph Circuits v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) A path can be represented by a sequence of vertices or by a sequence of directed edges

Connected Graphs An undirected graph G is said to be connected if for every u and v ∈ V there is a path between u and v. u1u1 u3u3 u2u2 u5u5 u4u4 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Example of a Disconnected Graph u1u1 u3u3 u2u2 u5u5 u4u4 u6u6 u7u7 u8u8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Directed Connected Graphs A directed graph G is said to be weakly connected if after removing the direction the graph is connected. A directed graph G is said to be strongly connected if for every u, v ∈ V(G) ∃ a directed path from u to v. Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

u1u1 u2u2 u3u3 u5u5 u8u8 u4u4 u7u7 Thanks: Meghna 22,Mrityunjaya 23, Vibha Yadav 47 (MCA 202) Example of a strongly connected graph

u1u1 u2u2 u4u4 u3u3 u6u6 u7u7 u5u5 u8u8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) Example of a graph that is weakly connected but not strongly connected

Degree of a Vertex In undirected graph G, degree(u) is defined as the number of edges incident on u. In a directed graph G, in-degree (u) is the number of edges with u as the arrow head. In a directed graph G, out-degree (v) is the number of edges with u as the tail of the arrow. Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

For an undirected graph, = 2|E| where, V is the vertex set, E denotes the set of edges of the graph and deg( v ) denotes the number of edges incident on vertex v. Proof : Base case: For a graph with only one vertex, deg( v 1 )=0 which is true as the number of edges are zero and therefore, 2|E| =0. Thanks Neelakshi Dang Roll No. 27 (MCA 2012) v1v1

For a graph with two vertex, Case(i) : when both vertex are disconnected, = deg(v 1 )+ deg(v 2 )=0 which is true as the number of edges for the graph is zero and therefore, 2|E| =0. Case(ii): when both vertex are connected, = deg(v 1 )+ deg(v 2 )= 1+1 =2 which is true as the number of edges for the graph is one therefore, 2|E| = 2(1) = 2. Thanks Neelakshi Dang Roll No. 27 (MCA 2012) v1v1 v2v2 v1v1 v2v2

Induction Hypothesis: Let the hypothesis hold for every graph of vertex size n, Let G be a graph with (n+1) vertices. Remove a vertex v* and all the edges incident on it, i.e. remove deg(v*) edges incident on v*, resulting in a graph G’ with n vertices. → = 2|E(G’)|by I.H. - Thanks Neelakshi Dang Roll No. 27 (MCA 2012) 1

Let deg(v*) = l, and let v 1, v 2, …, v l be the neighbors of v* in G, then deg G’ (v i ) = deg G (v i ) – 1, i = 1,2, …, l _ and deg G’ (v i ) = deg G (v i ), v≠v i → |E(G’)| = |E(G)| - l - From and, + = 2|E(G’)| → = 2|E(G’)|+ l - Thanks Neelakshi Dang Roll No. 27 (MCA 2012)

Adding deg(v*) to both sides of eq., we get = + deg G (v*) = 2|E(G’)|+ l + l = 2|E(G’)|+ 2 l = 2|E(G’)+ l | = 2|E(G)| (using ) Hence Proved. Thanks Neelakshi Dang Roll No. 27 (MCA 2012) 4 3

Acyclic Graph: A Graph with no cycles Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) A graph with no cycles

A connected graph with no cycles is called a tree. Thanks Nakul kumar Roll No.24,Navneet kumar Roll No.25(MCA 2012)

Three equivalent statements about trees T is a tree i.e. T is a connected acyclic graph. T is a connected graph with n-1 edges. There is a unique path between every pair of vertices. Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202)

Claim- A tree with n vertices has exactly (n-1) edges. Proof-: Base Case: for n=1. no. of edges =0. For n=2 No. of edges=1. Therefore, it holds true for n=1 and n=2. Induction Hypothesis: Let it be true for every tree with ≤ n vertices. Thanks Nakul kumar Roll No.24,Navneet kumar Roll No.25(MCA 2012)

Let T be a tree with n+1 vertices. Thanks Nakul kumar Roll No.24,Navneet kumar Roll No.25(MCA 2012)

After removing this edge we get two separate trees T1 and T2, such that E(T 1 ) U E(T 2 ) = E(T) – e and |V(T 1 )| ≤ n and |V(T 2 )| ≤ n |E(T 1 )| = |V(T 1 )|-1 (by induction hypothesis) |E(T 2 )| = |V(T 2 )|-1 ( by induction hypothesis) So, |E(T)| = |E(T 1 )|+|E(T 2 )|+1 |E(T)| = (|V(T 1 )|-1) + (|V(T 2 )|-1) + 1 = |V(T 1 )| + |V(T 2 )| - 1 = | V(T)| - 1 = n+1-1 = n Hence proved. Ex: Prove the converse i..e a connected graph with n-1 edges is acyclic. Thanks Nakul kumar Roll No.24,Navneet kumar Roll No.25(MCA 2012)

Exercise: Prove that T is a tree iff there exists a unique simple path between every pair of vertices. Proof: Using the definition of tree, If T is a tree, it is connected, i.e there exists some path between every pair of vertices. Suppose if possible, there exists two distinct paths between some pair of vertices ‘u’ and ‘v’. Thanks Nakul kumar Roll No.24,Navneet kumar Roll No.25(MCA 2012)

Without loss of generality, we assume that there is no common vertex between them. So, this shows there exists a cycle, which contradicts the definition of tree. Hence, a contradiction. Assignment: Prove the converse. Thanks Nakul kumar Roll No.24,Navneet kumar Roll No.25(MCA 2012)

Subgraphs v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) Let G=(V,E) be a graph, then H=(V’,E’) is a subgraph of G if E’ is a subset of E and V’ is a subset of V, such that u, v is in V’, for all (u,v) in E’.

Spanning Trees v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v8v8 Thanks: Meghna 22 and Mrityunjaya 23 (MCA 202) Given a graph G, a subgraph T of G is said to be a Spanning Tree if I.T is a tree II. T spans all the vertices of G.