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.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Lecture 5 Graph Theory. Graphs Graphs are the most useful model with computer science such as logical design, formal languages, communication network,
Graph-02.
Review Binary Search Trees Operations on Binary Search Tree
Introduction to Graphs
Graph A graph, G = (V, E), is a data structure where: V is a set of vertices (aka nodes) E is a set of edges We use graphs to represent relationships among.
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.
Computability and Complexity 23-1 Computability and Complexity Andrei Bulatov Search and Optimization.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R5. Graphs.
Graph & BFS.
Graphs Intro G.Kamberova, Algorithms Graphs Introduction Gerda Kamberova Department of Computer Science Hofstra University.
Connected Components, Directed Graphs, Topological Sort COMP171.
Introduction to Graphs
Lecture 14: Graph Algorithms Shang-Hua Teng. Undirected Graphs A graph G = (V, E) –V: vertices –E : edges, unordered pairs of vertices from V  V –(u,v)
Introduction to Graphs What is a Graph? Some Example applications of Graphs. Graph Terminologies. Representation of Graphs. –Adjacency Matrix. –Adjacency.
Connected Components, Directed Graphs, Topological Sort Lecture 25 COMP171 Fall 2006.
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.
Connected Components, Directed graphs, Topological sort COMP171 Fall 2005.
ALG0183 Algorithms & Data Structures Lecture 18 The basics of graphs. 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks.
Graphs Algorithm Design and Analysis Week 4 Bibliography: [CLRS]- Subchap 22.1 – Representation of Graphs.
GRAPH Learning Outcomes Students should be able to:
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
Data Structures Week 9 Further Data Structures The story so far  Saw some fundamental operations as well as advanced operations on arrays, stacks, and.
Intro to Graphs CSIT 402 Data Structures II. CSIT 402 Graph Introduction2 Graphs Graphs are composed of ›Nodes (vertices) Can be labeled ›Edges (arcs)
Graphs Chapter 10.
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,
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
1 CS104 : Discrete Structures Chapter V Graph Theory.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Markov Chains and Random Walks. Def: A stochastic process X={X(t),t ∈ T} is a collection of random variables. If T is a countable set, say T={0,1,2, …
Data Structures & Algorithms Graphs
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
CSS106 Introduction to Elementary Algorithms
CISC 235: Topic 9 Introduction to Graphs. CISC 235 Topic 92 Outline Graph Definition Terminology Representations Traversals.
Lecture 10: Graph-Path-Circuit
Introduction to Graph Theory
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,
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.
Graphs. Graph Definitions A graph G is denoted by G = (V, E) where  V is the set of vertices or nodes of the graph  E is the set of edges or arcs connecting.
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.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
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.
Subject Four Graphs Data Structures. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes.
Chapter Chapter Summary Graphs and Graph Models Graph Terminology and Special Types of Graphs Representing Graphs and Graph Isomorphism Connectivity.
Graph theory Definitions Trees, cycles, directed graphs.
Introduction to Graph Theory
Depth-First Search.
CS120 Graphs.
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 11 Graphs.
Connected Components, Directed Graphs, Topological Sort
ITEC 2620M Introduction to Data Structures
Graphs G = (V, E) V are the vertices; E are the edges.
CSC 380: Design and Analysis of Algorithms
GRAPHS Lecture 17 CS 2110 — Spring 2019.
Graphs G = (V,E) V is the vertex set.
For Friday Read chapter 9, sections 2-3 No homework
Presentation transcript:

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 to start from some landmass and using each bridge exactly once, return to the starting point.

Data Structures Week 9 Introduction to Graphs The above problem dates back to the 17 th century. Several people used to try to solve it. Euler showed that no solution exists for this problem. Further, he exactly characterized when a solution exists. By solving this problem, it is said that Euler started the study of graphs.

Data Structures Week 9 Introduction to Graphs The figure on the right shows the same situation modeled as a graph. There exist several such classical problems where graph theory has been used to arrive at elegant solutions.

Data Structures Week 9 Introduction to Graphs Another such problem: In any set of at least six persons, there are either three mutual acquaintances or three mutual strangers.

Data Structures Week 9 Introduction to Graphs Formally, let V be a set of points, also called as vertices. Let E ⊆ VxV be a subset of the cross product of V with itself. Elements of E are also called as edges. A graph can be seen as the tuple (V, E). Usually denoted by upper case letters G, H, etc.

Data Structures Week 9 Our Interest Understand a few terms associated with graphs. Study how to represent graphs in a computer program. Study how traverse graphs. Study mechanisms to find paths between vertices. Spanning trees And so on...

Data Structures Week 9 Few Terms Recall that a graph G = (V, E) is a tuple with E being a subset of VxV. Scope for several variations: for u, v in V  Should we treat (u,v) as same as (v,u)?

Data Structures Week 9 Few Terms Recall that a graph G = (V, E) is a tuple with E being a subset of VxV. Scope for several variations: for u, v in V  Should we treat (u,v) as same as (v,u)? In this case, the graph is called as a undirected graph.  Treat (u,v) as different from (v,u).

Data Structures Week 9 Few Terms Recall that a graph G = (V, E) is a tuple with E being a subset of VxV. Scope for several variations: for u, v in V  Should we treat (u,v) as same as (v,u)? In this case, the graph is called as a undirected graph.  Treat (u,v) as different from (v,u). In this case, the graph is called as a directed graph.  Should we allow (u,u) in E? Edges of this kind are called as self-loops.

Data Structures Week 9 Undirected Graphs In this case, the edge (u,v) is same as the edge (v,u).  Normally written as edge uv

Data Structures Week 9 Undirected Graphs The degree of a node v in a graph G = (V,E) is the number of its neighbours.  It is denoted by d(v). In the above example, the degree of vertex 4 is 4. The neighbors of vertex 4 are {3, 5, 6, 7}. The degree of a graph G = (V,E) is the maximum degree of any node in the graph and is denoted  G). Sometimes, written as just  when G is clear from the context.  Thus,  = max v ∈ V d(v).  Thus  = 6 for the above graph.

Data Structures Week 9 Some Terms In a graph G = (V,E), a path is a sequence of vertices v1, v2, · · ·, vi, all distinct, such that v k v k+1 ∈ E for 1 ≤ k ≤ i − 1. If, under the above conditions, v1 = vi then it is called a cycle. The length of such a path(cycle) is i − 1(resp. i). An example: 3 – 8 – 5 – 2 in the above graph is a path from vertex 3 to vertex 2. Similarly, 2 – 7 – 6 – 5 – 2 is a cycle.

Data Structures Week 9 Directed Graphs In this case, the edge (u,v) is distinct from the edge (v,u).  Normally written as edge 〈 u, v 〉

Data Structures Week 9 Directed Graphs Have to alter the definition of degree as in-degree(v) : the number of neighbors w of v such that (w,v) in E. out-degree(v) : the number of neighbors w of v such that (v,w) in E. in-degree(4) = 1 out-degree(2) = 2.

Data Structures Week 9 Directed Graphs Have to alter the definition of path and cycle to directed path and directed cycle.

Data Structures Week 9 Representing Graphs How to represent graphs in a computer program. Several ways possible.

Data Structures Week 9 Adjacency Matrix The graph is represented by an n × n–matrix where n is the number of vertices. Let the matrix be called A. Then the element A[i, j] is set to 1 if (i, j) ∈ E(G) and 0 otherwise, where 1 ≤ i, j ≤ n. The space required is O(n 2 ) for a graph on n vertices. By far the simplest representation. Many algorithms work very efficiently under this representation.

Data Structures Week 9 Adjacency Matrix Example A

Data Structures Week 9 Adjacency Matrix Observations Space required is n 2 The matrix is symmetric and 0,1—valued.  For directed graphs, the matrix need not be symmetric. Easy to check for any u,v whether uv is an edge. Most algorithms also take O(n 2 ) time in this representation. The following is an exception: The Celebrity Problem.

Data Structures Week 9 Adjacency List Imagine a list for each vertex that will contain the list of neighbours of that vertex. The space required will only be O(m). However, one drawback is that it is difficult to check whether a particular pair (i, j) is an edge in the graph or not.

Data Structures Week 9 Adjacency List Example

Data Structures Week 9 Adjacency List Useful representation for sparse graphs. Extends to also directed graphs.

Data Structures Week 9 Other Representations Neighbor maps