Inf 496/596 Topics in Informatics: Analysis of Social Network Data Jagdish S. Gangolly Department of Informatics College of Computing & Information State University of New York at Albany Lecture 1B (Graphs) March 23, 2013
Table of Contents A Motivating example of a network: Königsburgh Problem (Euler, 1735) Basic Concepts Types of Graphs Elementary Graph Theory Definition of a graph Kinds of Graphs: Multigraph and Simple graph Kinds of Graphs: Undirected graph and Directed graphs Data Structures for graphs: lists and matrices Graph Data Structures: An Example
A Motivating example of a network: Königsburgh Problem
Basic Graph Concepts Vertex: Nodes or points usually represent objects Edge/line and arc/arrow: usually represent relations Size of a Graph: The number of edges in the graph, or E Order of a Graph: The number of vertices in the graph, or V Incidence: is a relation that associates with each edge two vertices. Adjacency: Any two vertices u and v are said to be adjacent is there is an edge e that is incident with u and v.
Types of Graphs Undirected graph: The edges have no orientation Directed graph: The arcs (sometimes called directed edges or arrows) have an orientation. An arc a = (x, y) is considered to be directed from x to y; y is called the head and x is called the tail of the arc; y is said to be a direct successor of x, and x is said to be a direct predecessor of y. (Wikipedia) Simple graph: is a graph which has no loops (relation between a vertex and itself) and no more than one edge between any two vertices. Multigraph: a graph with loops, and multiple edges between vertices. Weighted graph: the edges are weighted (i.e.., edges have attributes). Weighted graphs are called networks.
Types of Graphs (Continued) Labelled Graph: where vertices and edges have labels Bipartite Graph: where there are two types of vertices and no edges between vertices of the same type Planar Graph: is a graph whose vertices and edges can be drawn in a plane such that no two of the edges intersect Connected Graph: In an undirected graph G, two vertices u and v are called connected if G contains a path from u to v. Otherwise, they are called disconnected. A graph is called connected if every pair of distinct vertices in the graph is connected; otherwise, it is called disconnected. Weakly Connected Graph: A directed graph is called weakly connected if replacing all of its directed edges with undirected edges produces a connected (undirected) graph.
Types of Graphs (Continued) Strongly Connected Graph: A directed graph is strongly connected or strong if it contains a directed path from u to v and a directed path from v to u for every pair of vertices u, v. Tree: is a connected graph with no cycles. Forest: is a graph with no cycles (i.e. the disjoint union of one or more trees). Hypergraph: a graph where an edge can join more than two vertices.
Elementary Graph Theory: Definition of a graph) An (undirected) Graph G is an ordered pair G = (V, E) where the vertex set V = {v 1, v 2,..., v n }, the edge set E = {e 1, e 2,..., e m } and E = {e 1, e 2,..., e m } {{x, y} V } An Example: V = {v 0, v 1, v 2, v 3 }, V = {e 0, e 1, e 2, e 3 } = {{v 0, v 1 }, {v 1, v 2 }, {v 2, v 3 }, {v 3, v 0 }},, v 0 v 1 v 3 v 2
Kinds of Graphs: Multigraph and Simple graph A graph that has loops and multiple edges between the same nodes is called a multigraph. An example is the following: Source: http://en.wikipedia.org/wiki/multigraph A multigraph that has no loops or multiple edges that share the same nodes is called a simple graph. The graph on the previous slide is a simple graph.
Kinds of Graphs: Undirected graph and Directed graphs In the graph in the previous slides, the edges did not have a direction. If the edges have a direction, the graph is called a directed graph. The edges of a directed graph are sometimes called arrows. See the example below: In the above, we have assumed that the nodes and the edges are primitives in that they do not hold any information beyond their labels or names. However, that models just the structure of the graph, and is not rich enough to study most phenomena. But it is possible to semantically enrich the graph model by having the nodes and edges carry more information besides their labels. For example, in a social networks application, the nodes may represent persons, and the edges may represent the interactions between such persons. The attributes of the persons as well as the attributes relating to the nature of the interactions, and the frequency of the interactions can be incorporated into the model.
Data Structures for graphs: lists and matrices Data relating to social graphs can be represented as lists or matrices. List: Incidence List The edges can be represented as an array of pairs of the nodes that they are incident to. This representation is edge-centric Adjacency List For each node a list of neighbors (nodes with which it shares an edge) Matrices: Incidence Matrix In the incidence matrix the rows represent vertices and the columns represent the edges. The cells take a value 1 if the edge is incident to the node. So each column contains precisely two ones and rest of the cells have zeroes Adjacency matrix In the adjacency matrix both the rows and columns represent vertices. The cell (i, j) takes a value 1 if there is an edge from vertex i to vertex j Distance Matrix Both rows and columns represent vertices. The cell (i, j) takes a value of the distance between vertex i and j, where distance is defined as the length of the path between i and j (number of hops) Laplacian or Kirchoff Matrix Contains information relating to the degree of nodes (number of edges incident to the nodes) as well as adjacency information
Graph Data Structures: An Example (Incidence List) Consider the simple graph G = (V, E) where {V = 1, 2, 3, 4, 5; E = {(1, 2), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (4, 2)} Incidence list: 1 : {(1, 2), (1, 5)} 2 : {(2, 1), (2, 3), (2, 4), (2, 5)} 3 : {(3, 2), (3, 4)} 4 : {(4, 2), (4, 3), (4, 5)} 5 : {(5, 1), (5, 2), (5, 4)} Source: http://www.cs.sunysb.edu/ algorith/files/graph-data-structures.shtml
Graph Data Structures: An Example (Adjacency List) Graph: Adjacency List: 1: {2, 5} 2: {1, 3, 4, 5} 3: {2, 4} 4: {2, 3, 5}
Graph Data Structures: An Example (Incidence Matrix) Graph: Incidence Matrix: 1 0 0 1 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 0 0 1 1 1 0 0
Graph Data Structures: An Example (Adjacency Matrix) Graph: Graph: Adjacency Matrix: 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0
Graph Data Structures: An Example (Distance Matrix) Graph: Distance Matrix: 0 1 2 2 1 1 0 1 1 1 2 1 0 1 2 2 1 1 0 1 1 1 2 1 0