Graph Theory Review. January 30, Network Science Analytics Graph Theory Review 1

Similar documents
Graph and Digraph Glossary

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

Graph. Vertex. edge. Directed Graph. Undirected Graph

Introduction III. Graphs. Motivations I. Introduction IV

Mining Social Network Graphs

Graph Theory. ICT Theory Excerpt from various sources by Robert Pergl

Varying Applications (examples)

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

Course Introduction / Review of Fundamentals of Graph Theory

Chapter 2 Graphs. 2.1 Definition of Graphs

MATH 363 Final Wednesday, April 28. Final exam. You may use lemmas and theorems that were proven in class and on assignments unless stated otherwise.

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

1 Graphs and networks

Social Network Analysis

Algorithm Design (8) Graph Algorithms 1/2

Introduction to Graph Theory

An Exploratory Journey Into Network Analysis A Gentle Introduction to Network Science and Graph Visualization

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory

Alessandro Del Ponte, Weijia Ran PAD 637 Week 3 Summary January 31, Wasserman and Faust, Chapter 3: Notation for Social Network Data

An Introduction to Graph Theory

Characterizing Graphs (3) Characterizing Graphs (1) Characterizing Graphs (2) Characterizing Graphs (4)

Copyright 2000, Kevin Wayne 1

5 Graphs

On the Relationships between Zero Forcing Numbers and Certain Graph Coverings

Graph Theory CS/Math231 Discrete Mathematics Spring2015

Graph Theory. Part of Texas Counties.

Lecture 5: Graphs & their Representation

Extracting Information from Complex Networks

CSI 604 Elementary Graph Algorithms

Social-Network Graphs

Lecture 3: Recap. Administrivia. Graph theory: Historical Motivation. COMP9020 Lecture 4 Session 2, 2017 Graphs and Trees

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CS473-Algorithms I. Lecture 13-A. Graphs. Cevdet Aykanat - Bilkent University Computer Engineering Department

Module 11. Directed Graphs. Contents

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

CS224W: Analysis of Networks Jure Leskovec, Stanford University

Algorithms: Graphs. Amotz Bar-Noy. Spring 2012 CUNY. Amotz Bar-Noy (CUNY) Graphs Spring / 95

Introduction aux Systèmes Collaboratifs Multi-Agents

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

Copyright 2000, Kevin Wayne 1

3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications

CSC Intro to Intelligent Robotics, Spring Graphs

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Graph Algorithms. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Elements of Graph Theory

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

Undirected Graphs. Hwansoo Han

Logic: The Big Picture. Axiomatizing Arithmetic. Tautologies and Valid Arguments. Graphs and Trees

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Algorithm Design and Analysis

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

16 - Networks and PageRank

Algorithms. Graphs. Algorithms

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Graph Theory for Network Science

Unit 2: Graphs and Matrices. ICPSR University of Michigan, Ann Arbor Summer 2015 Instructor: Ann McCranie

Discrete mathematics II. - Graphs

Graphs. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1

Graph Theory for Network Science

3.1 Basic Definitions and Applications

0.0.1 Network Analysis

Part II. Graph Theory. Year

1 Digraphs. Definition 1

Social Network Analysis

Chapter 11: Graphs and Trees. March 23, 2008

Non Overlapping Communities

Lecture 1: Examples, connectedness, paths and cycles

UNDIRECTED GRAPH: a set of vertices and a set of undirected edges each of which is associated with a set of one or two of these vertices.

Number Theory and Graph Theory

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

CS781 Lecture 2 January 13, Graph Traversals, Search, and Ordering

Signal Processing for Big Data

Graph Search. Adnan Aziz

Lecture 3: Graphs and flows

CMSC 380. Graph Terminology and Representation

Chapter 9 Graph Algorithms

Assignment 4 Solutions of graph problems

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Chapter 4. Relations & Graphs. 4.1 Relations. Exercises For each of the relations specified below:

Graphs & Digraphs Tuesday, November 06, 2007

CS6200 Information Retreival. The WebGraph. July 13, 2015

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV


Konigsberg Bridge Problem

Graph Theory. Probabilistic Graphical Models. L. Enrique Sucar, INAOE. Definitions. Types of Graphs. Trajectories and Circuits.

Solving problems on graph algorithms

6. Lecture notes on matroid intersection

Introduction to Mathematical Programming IE406. Lecture 16. Dr. Ted Ralphs

CS388C: Combinatorics and Graph Theory

Graphs. Motivations: o Networks o Social networks o Program testing o Job Assignment Examples: o Code graph:

Graph Representations and Traversal

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

Lecture 22 Tuesday, April 10

Graphs Definitions. Gunnar Gotshalks. GraphDefinitions 1

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

Definition of Graphs and Trees. Representation of Trees.

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

Transcription:

Graph Theory Review Gonzalo Mateos Dept. of ECE and Goergen Institute for Data Science University of Rochester gmateosb@ece.rochester.edu http://www.ece.rochester.edu/~gmateosb/ January 30, 2018 Network Science Analytics Graph Theory Review 1

Basic definitions and concepts Basic definitions and concepts Movement in a graph and connectivity Families of graphs Algebraic graph theory Graph data structures and algorithms Network Science Analytics Graph Theory Review 2

Graphs 5 1 6 2 3 Graph G(V, E) A set V of vertices or nodes Connected by a set E of edges or links Elements of E are unordered pairs (u, v), u, v V In figure Vertices are V = {1, 2, 3,, 5, 6} Edges E = {(1, 2), (1, 5),(2, 3), (3, ),... (3, 5), (3, 6), (, 5), (, 6)} Often we will say graph G has order N v := V, and size N e := E Network Science Analytics Graph Theory Review 3

From networks to graphs Networks are complex systems of inter-connected components Graphs are mathematical representations of these systems Formal language we use to talk about networks Components: nodes, vertices V Inter-connections: links, edges E Systems: networks, graphs G(V, E) Network Science Analytics Graph Theory Review

Vertices and edges in networks Network Vertex Edge Internet Computer/router Cable or wireless link Metabolic network Metabolite Metabolic reaction WWW Web page Hyperlink Food web Species Predation Gene-regulatory network Gene Regulation of expression Friendship network Person Friendship or acquaintance Power grid Substation Transmission line Affiliation network Person and club Membership Protein interaction Protein Physical interaction Citation network Article/patent Citation Neural network Neuron Synapse... Network Science Analytics Graph Theory Review 5

Simple and multi-graphs In general, graphs may have self-loops and multi-edges A graph with either is called a multi-graph 5 1 6 2 3 Mostly work with simple graphs, with no self-loops or multi-edges 5 1 6 2 3 Network Science Analytics Graph Theory Review 6

Directed graphs 5 1 6 2 3 In directed graphs, elements of E are ordered pairs (u, v), u, v V Means (u, v) distinct from (v, u) Directed edges are called arcs Directed graphs often called digraphs By convention arc (u, v) points to v If both {(u, v), (v, u)} E, the arcs are said to be mutual Ex: who-calls-whom phone networks, Twitter follower networks Network Science Analytics Graph Theory Review 7

Subgraphs Consider a given graph G(V, E) 5 1 6 2 3 Def: Graph G (V, E ) is an induced subgraph of G if V V and E E is the collection of edges in G among that subset of vertices Ex: Graph induced by V = {1,, 5} 1 5 Network Science Analytics Graph Theory Review 8

Weighted graphs Oftentimes one labels vertices, edges or both with numerical values Such graphs are called weighted graphs Useful in modeling are e.g., Markov chain transition diagrams Ex: Single server queuing system (M/M/1 queue) λ µ λ λ λ λ 0... i 1 i i +1... µ µ µ Labels could correspond to measurements of network processes Ex: Node is infected or not with influenza, IP traffic carried by a link Network Science Analytics Graph Theory Review 9

Typical network representations Network WWW Facebook friendships Citation network Collaboration network Mobile phone calls Protein interaction. Graph representation Directed multi-graph (with loops), unweighted Undirected, unweighted Directed, unweighted, acyclic Undirected, unweighted Directed, weighted Undirected multi-graph (with loops), unweighted. Note that multi-edges are often encoded as edge weights (counts) Network Science Analytics Graph Theory Review 10

Adjacency Useful to develop a language to discuss the connectivity of a graph A simple and local notion is that of adjacency Vertices u, v V are said adjacent if joined by an edge in E Edges e 1, e 2 E are adjacent if they share an endpoint in V 5 1 6 2 3 In figure Vertices 1 and 5 are adjacent; 2 and are not Edge (1, 2) is adjacent to (1, 5), but not to (, 6) Network Science Analytics Graph Theory Review 11

Degree An edge (u, v) is incident with the vertices u and v Def: The degree d v of vertex v is its number of incident edges Degree sequence arranges degrees in non-decreasing order 3 3 2 5 2 1 2 6 2 3 In figure Vertex degrees shown in red, e.g., d 1 = 2 and d 5 = 3 Graph s degree sequence is 2,2,2,3,3, High-degree vertices likely influential, central, prominent. More soon Network Science Analytics Graph Theory Review 12

Properties and observations about degrees Degree values range from 0 to N v 1 The sum of the degree sequence is twice the size of the graph N v v=1 d v = 2 E = 2N e The number of vertices with odd degree is even In digraphs, we have vertex in-degree d in v 3, 1 2, 2 and out-degree d out v 0, 2 1 5 1, 2 1, 2 2 3 2, 0 6 In figure Vertex in-degrees shown in red, out-degrees in blue For example, d1 in out = 0, d1 = 2 and d5 in out = 3, d5 = 1 Network Science Analytics Graph Theory Review 13

Movement in a graph and connectivity Basic definitions and concepts Movement in a graph and connectivity Families of graphs Algebraic graph theory Graph data structures and algorithms Network Science Analytics Graph Theory Review 1

Movement in a graph Def: A walk of length l from v 0 to v l is an alternating sequence {v 0, e 1, v 1,..., v l 1, e l, v l }, where e i is incident with v i 1, v i A trail is a walk without repeated edges A path is a walk without repeated nodes (hence, also a trail) 5 1 6 2 3 A walk or trail is closed when v 0 = v l. A closed trail is a circuit A cycle is a closed walk with no repeated nodes except v 0 = v l All these notions generalize naturally to directed graphs Network Science Analytics Graph Theory Review 15

Connectivity Vertex v is reachable from u if there exists a u v walk Def: Graph is connected if every vertex is reachable from every other 1 5 2 3 6 7 If bridge edges are removed, the graph becomes disconnected Network Science Analytics Graph Theory Review 16

Connected components Def: A component is a maximally connected subgraph Maximal means adding a vertex will ruin connectivity 1 5 2 3 6 7 In figure Components are {1, 2, 5, 7}, {3, 6} and {} Subgraph {3,, 6} not connected, {1, 2, 5} not maximal Disconnected graphs have 2 or more components Largest component often called giant component Network Science Analytics Graph Theory Review 17

Giant connected components Large real-world networks typically exhibit one giant component Ex: romantic relationships in a US high school [Bearman et al 0] 2 2 9 63 1 Q: Why do we expect to find a single giant component? A: Well, it only takes one edge to merge two giant components Network Science Analytics Graph Theory Review 18

Connectivity of directed graphs Connectivity is more subtle with directed graphs. Two notions Def: Digraph is strongly connected if for every pair u, v V, u is reachable from v (via a directed walk) and vice versa Def: Digraph is weakly connected if connected after disregarding arc directions, i.e., the underlying undirected graph is connected 5 1 6 2 3 Above graph is weakly connected but not strongly connected Strong connectivity obviously implies weak connectivity Network Science Analytics Graph Theory Review 19

How well connected nodes are? Q: Which node is the most connected? A: Node rankings to measure website relevance, social influence There are two important connectivity indicators How many links point to a node (outgoing links irrelevant) How important are the links that point to a node 5 1 6 2 3 Idea exploited by Google s PageRank c to rank webpages... by social scientists to study trust & reputation in social networks... by ISI to rank scientific papers, journals... More soon Network Science Analytics Graph Theory Review 20

Families of graphs Basic definitions and concepts Movement in a graph and connectivity Families of graphs Algebraic graph theory Graph data structures and algorithms Network Science Analytics Graph Theory Review 21

Complete graphs and cliques A complete graph K n of order n has all possible edges K 2 K 3 K K 5 Q: What is the size of K n? A: Number of edges in K n = Number of vertex pairs = ( ) n 2 = n(n 1) 2 Of interest in network analysis are cliques, i.e., complete subgraphs Extreme notions of cohesive subgroups, communities Network Science Analytics Graph Theory Review 22

Regular graphs A d-regular graph has vertices with equal degree d Naturally, the complete graph K n is (n 1)-regular Cycles are 2-regular (sub) graphs Regular graphs arise frequently in e.g., Physics and chemistry in the study of crystal structures Geo-spatial settings as pixel adjacency models in image processing Opinion formation, information cycles as regular subgraphs Network Science Analytics Graph Theory Review 23

Trees and directed acyclic graphs A tree is a connected acyclic graph. An acyclic graph is forest Ex: river network, information cascades in Twitter, citation network Tree Directed tree DAG A directed tree is a digraph whose underlying undirected graph is a tree Root is only vertex with paths to all other vertices Vertex terminology: parent, children, ancestor, descendant, leaf The underlying graph of a directed acyclic graph (DAG) is not a tree DAGs have a near-tree structure, also useful for algorithms Network Science Analytics Graph Theory Review 2

Bipartite graphs A graph G(V, E) is called bipartite when V can be partitioned in two disjoint sets, say V 1 and V 2 ; and Each edge in E has one endpoint in V 1, the other in V 2 v6 v7 v8 v2 v3 v1 v1 v2 v3 v v5 v v5 Useful to represent e.g., membership or affiliation networks Nodes in V 1 could be people, nodes in V 2 clubs Induced graph G(V 1, E 1 ) joins members of same club Network Science Analytics Graph Theory Review 25

Planar graphs A graph G(V, E) is called planar if it can be drawn in the plane so that no two of its edges cross each other Planar graphs can be drawn in the plane using straight lines only Useful to represent or map networks with a spatial component Planar graphs are rare Some mapping tools minimize edge crossings Network Science Analytics Graph Theory Review 26

Algebraic graph theory Basic definitions and concepts Movement in a graph and connectivity Families of graphs Algebraic graph theory Graph data structures and algorithms Network Science Analytics Graph Theory Review 27

Adjacency matrix Algebraic graph theory deals with matrix representations of graphs Q: How can we capture the connectivity of G(V, E) in a matrix? A: Binary, symmetric adjacency matrix A {0, 1} Nv Nv, with entries A ij = { 1, if (i, j) E 0, otherwise. Note that vertices are indexed with integers 1,..., N v Binary and symmetric A for unweighted and undirected graph In words, A is one for those entries whose row-column indices denote vertices in V joined by an edge in E, and is zero otherwise Network Science Analytics Graph Theory Review 28

Adjacency matrix examples Examples for undirected graphs and digraphs 1 1 2 3 2 3 A u = 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0, A d = 0 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 If the graph is weighted, store the (i, j) weight instead of 1 Network Science Analytics Graph Theory Review 29

Adjacency matrix properties Adjacency matrix useful to store graph structure. More soon Also, operations on A yield useful information about G Degrees: Row-wise sums give vertex degrees, i.e., N v j=1 A ij = d i For digraphs A is not symmetric and row-, colum-wise sums differ N v j=1 A ij = d out i, N v i=1 A ij = d in j Walks: Let A r denote the r-th power of A, with entries A (r) ij Then A (r) ij yields the number of i j walks of length r in G Corollary: tr(a 2 )/2 = N e and tr(a 3 )/6 = # in G Spectrum: G is d-regular if and only if 1 is an eigenvector of A, i.e., A1 = d1 Network Science Analytics Graph Theory Review 30

Incidence matrix A graph can be also represented by its N v N e incidence matrix B B is in general not a square matrix, unless N v = N e For undirected graphs, the entries of B are B ij = { 1, if vertex i incident to edge j 0, otherwise. For digraphs we also encode the direction of the arc, namely 1, if edge j is (k, i) B ij = 1, if edge j is (i, k). 0, otherwise Network Science Analytics Graph Theory Review 31

Incidence matrix examples Examples for undirected graphs and digraphs 1 e 1 2 1 e 5 e 3 e 1 e 3 e 2 2 e 3 e 5 e 3 e 2 B u = 1 0 1 0 1 1 1 0 0 0 0 0 0 1 1 0 1 1 1 0, B d = 1 0 1 0 1 1 1 0 0 0 0 0 0 1 1 0 1 1 1 0 If the graph is weighted, modify nonzero entries accordingly Network Science Analytics Graph Theory Review 32

Graph Laplacian Vertex degrees often stored in the diagonal matrix D, where D ii = d i D = 2 0 0 0 0 2 0 0 0 0 1 0 0 0 0 3 1 2 3 The N v N v symmetric matrix L := D A is called graph Laplacian d i, if i = j L ij =, L = 1, if (i, j) E 0, otherwise 2 1 0 1 1 2 0 1 0 0 1 1 1 1 1 3 Network Science Analytics Graph Theory Review 33

Laplacian matrix properties Smoothness: For any vector x R Nv of vertex values, one has x Lx = (x i x j ) 2 (i,j) E which can be minimized to enforce smoothness of functions on G Positive semi-definiteness: Follows since x Lx 0 for all x R Nv Rank deficiency: Since L1 = 0, L is rank deficient Spectrum and connectivity: The smallest eigenvalue λ 1 of L is 0 If the second-smallest eigenvalue λ2 0, then G is connected If L has n zero eigenvalues, G has n connected components Network Science Analytics Graph Theory Review 3

Graph data structures and algorithms Basic definitions and concepts Movement in a graph and connectivity Families of graphs Algebraic graph theory Graph data structures and algorithms Network Science Analytics Graph Theory Review 35

Graph data structures and algorithms Q: How can we store and analyze a graph G using a computer? Purely mathematical objects Graph data structures and algorithms Practical tools for network analytics Data structures: efficient storage and manipulation of a graph Algorithms: scalable computational methods for graph analytics Contributions in this area primarily due to computer science Network Science Analytics Graph Theory Review 36

Adjacency matrix as a data structure Q: How can we represent and store a graph G in a computer? A: The N v N v adjacency matrix A is a natural choice A ij = { 1, if (i, j) E 0, otherwise. A = 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 2 3 Matrices (arrays) are basic data objects in software environments Naive memory requirement is O(N 2 v ) May be undesirable for large, sparse graphs Network Science Analytics Graph Theory Review 37

Networks are sparse graphs Most real-world networks are sparse, meaning N e N v (N v 1) 2 or equivalently d := 1 N v N v v=1 d v N v 1 Figures from the study by Leskovec et al 09 are eloquent Network dataset Order N v Avg. degree d WWW (Stanford-Berkeley) 319,717 9.65 Social network (LinkedIn) 6,96,668 8.87 Communication (MSN IM) 22,720,596 11.1 Collaboration (DBLP) 317,080 6.62 Roads (California) 1,957,027 2.82 Proteins (S. Cerevisiae) 1,870 2.39 Graph density ρ := Ne N 2 v = d 2N v is another useful metric Network Science Analytics Graph Theory Review 38

Adjacency and edge lists An adjacency-list representation of graph G is an array of size N v The i-th array element is a list of the vertices adjacent to i L a [1] = {2, } 1 L a [2] = {1, } L a [3] = {} L a [] = {1, 2, 3} 2 3 Similarly, an edge list stores the vertex pairs incident to each edge L e [1] = {1, 2} L e [2] = {1, } L e [3] = {2, } L e [] = {3, } In either case, the memory requirement is O(N e ) Network Science Analytics Graph Theory Review 39

Graph algorithms and complexity Numerous interesting questions may be asked about a given graph For few simple ones, lookup in data structures suffices Q1: Are vertices u and v linked by an edge? Q2: What is the degree of vertex u? Some others require more work. Still can tackle them efficiently Q1: What is the shortest path between vertices u and v? Q2: How many connected components does the graph have? Q3: Is a given digraph acyclic? Unfortunately, in some cases there is likely no efficient algorithm Q1: What is the maximal clique in a given graph? Algorithmic complexity key in the analysis of modern network data Network Science Analytics Graph Theory Review 0

Testing for connectivity Goal: verify connectivity of a graph based on its adjacency list Idea: start from vertex s, explore the graph, mark vertices you visit Output : List M of marked vertices in the component Input : Graph G (e.g., adjacency list) Input : Starting vertex s L := {s}; M := {s}; % Initialize exploration and marking lists % Repeat while there are still nodes to explore while L do choose u L; % Pick arbitrary vertex to explore if (u, v) E such that v / M then choose (u, v) with v of smallest index; L := L {v}; M := M {v}; % Mark and augment else L := L \ {u}; % Prune end end Network Science Analytics Graph Theory Review 1

Graph exploration example Below we indicate the chosen and marked nodes. Initialize s = 2 L Mark {2} 2 {2,1} 1 {2,1,5} 5 {2,1,5,6} 6 {1,5,6} {1,5,6,} {5,6,} {5,} {5,,3} 3 {5,3} {5,3,7} 7 {5,3} {3} {3,8} 8 {3} {} S1 2 S2 2 S3 5 7 5 7 1 6 8 1 6 8 1 3 3 S 2 S5 2 S6 5 7 5 7 1 6 8 1 6 8 1 3 3 S7 2 S8 2 5 7 5 7 1 6 8 1 6 8 3 3 2 2 5 7 6 3 5 7 6 3 8 8 Exploration takes 2N v steps. Each node is added and removed once Network Science Analytics Graph Theory Review 2

Breadth-first search Choices made arbitrarily in the exploration algorithm. Variants? Breadth-first search (BFS): choose for u the first element of L Output : List M of marked vertices in the component Input : Graph G (e.g., adjacency list) Input : Starting vertex s L := {s}; M := {s}; % Initialize exploration and marking lists % Repeat while there are still nodes to explore while L do u := first(l); % Breadth first if (u, v) E such that v / M then choose (u, v) with v of smallest index; L := L {v}; M := M {v}; % Mark and augment else L := L \ {u}; % Prune end end Network Science Analytics Graph Theory Review 3

BFS example Below we indicate the chosen and marked nodes. Initialize s = 2 L Mark {2} 2 {2,1} 1 {2,1,5} 5 {1,5} {1,5,} {1,5,,6} 6 {5,,6} {,6} {,6,3} 3 {6,3} {3} {3,7} 7 {3,7,8} 8 {7,8} {8} {} S1 2 S2 2 S3 5 7 5 7 1 6 8 1 6 8 1 3 3 S 2 S5 2 S6 5 7 5 7 1 6 8 1 6 8 1 3 3 S7 2 S8 2 5 7 5 7 1 6 8 1 6 8 3 3 2 2 5 7 6 3 5 7 6 3 8 8 The algorithm builds a wider tree (breadth first) Network Science Analytics Graph Theory Review

Depth-first search Depth-first search (DFS): choose for u the last element of L Output : List M of marked vertices in the component Input : Graph G (e.g., adjacency list) Input : Starting vertex s L := {s}; M := {s}; % Initialize exploration and marking lists % Repeat while there are still nodes to explore while L do u := last(l); % Depth first if (u, v) E such that v / M then choose (u, v) with v of smallest index; L := L {v}; M := M {v}; % Mark and augment else L := L \ {u}; % Prune end end Network Science Analytics Graph Theory Review 5

DFS example Below we indicate the chosen and marked nodes. Initialize s = 2 L Mark {2} 2 {2,1} 1 {2,1,} {2,1,,3} 3 {2,1,,3,7} 7 {2,1,,3} {2,1,,3,8} 8 {2,1,,3} {2,1,} {2,1,,6} 6 {2,1,,6,5} 5 {2,1,,6} {2,1,} {2,1} {2} {} S1 2 5 1 6 S2 2 S3 7 5 7 8 1 6 8 1 3 3 S 2 S5 2 S6 5 7 5 7 1 6 8 1 6 8 1 3 3 S7 2 S8 2 5 7 5 7 1 6 8 1 6 8 3 3 2 2 5 7 6 3 5 7 6 3 8 8 The algorithm builds longer paths (depth first) Network Science Analytics Graph Theory Review 6

Distances in a graph Recall a path {v 0, e 1, v 1,..., v l 1, e l, v l } has length l Edges weights {w e }, length of the walk is w e1 +... + w el Def: The distance between vertices u and v is the length of the shortest u v path. Oftentimes referred to as geodesic distance In the absence of a u v path, the distance is The diameter of a graph is the value of the largest distance Q: What are efficient algorithms to compute distances in a graph? A: BFS (for unit weights) and Dijkstra s algorithm Network Science Analytics Graph Theory Review 7

Computing distances with BFS Use BFS and keep track of path lengths during the exploration Increment distance by 1 every time a vertex is marked Output : Vector d of distances from reference vertex Input : Graph G (e.g., adjacency list) Input : Reference vertex s L := {s}; M := {s}; d(s) = 0; % Initialization % Repeat while there are still nodes to explore while L do u := first(l); % Breadth first if (u, v) E such that v / M then choose (u, v) with v of smallest index; L := L {v}; M := M {v};% Mark and augment d(v) := d(u) + 1 % Increment distance else L := L \ {u}; % Prune end end Network Science Analytics Graph Theory Review 8

Example: Distances in a social network BFS tree output for your friendship network Network Science Analytics Graph Theory Review 9

Glossary (Di) Graph Arc (Induced) Subgraph Incidence Degree sequence Walk, trail and path Connected graph Giant connected component Strongly connected digraph Clique Tree Bipartite graph Directed acyclic graph (DAG) Adjacency matrix Graph Laplacian Adjacency and edge lists Sparse graph Graph density Breadth-first search Depth-first search (DFS) Geodesic distance (BFS) Diameter Network Science Analytics Graph Theory Review 50