Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees Directed Graph and Binary Trees Math 301 Dr. Nahid Sultana December 19, 2012 Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees Introduction Directed Graph Basic Definitions Degrees Paths Adjacency matrix and Linked Representation Binary Trees Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Directed graphs are graphs in which the edges are one-way. I This type of graphs are frequently more useful in various dynamic systems such as digital computers or flow systems. I In this lecture the basic definitions and properties of directed graphs will be discussed. I Many of the definitions are similar to those in the last chapter on graph theory. I The binary trees will also be discussed in this lecture which is a fundamental structure in mathematics and computer science Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I A directed graph G (V , E ) or digraph (or simply graph) consists of two things: 1. A set V whose elements are called vertices, nodes, or points. 2. A set E of ordered pairs (u, v ) of vertices called arcs or directed edges or simply edges. I We write V (G ) and E (G ) to denote the set of vertices and the set of edges of a graph G, respectively. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Suppose e = (u, v ) is a directed edge in a digraph G . Then the following terminology is used: 1. e begins at u and ends at v . 2. u is the origin or initial point of e, and v is the destination or terminal point of e. 3. v is a successor of u. 4. u is adjacent to v , and v is adjacent from u. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Suppose e = (u, v ) is a directed edge in a digraph G . Then the following terminology is used: 1. e begins at u and ends at v . 2. u is the origin or initial point of e, and v is the destination or terminal point of e. 3. v is a successor of u. 4. u is adjacent to v , and v is adjacent from u. I If u = v , then e is called a loop. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Suppose e = (u, v ) is a directed edge in a digraph G . Then the following terminology is used: 1. e begins at u and ends at v . 2. u is the origin or initial point of e, and v is the destination or terminal point of e. 3. v is a successor of u. 4. u is adjacent to v , and v is adjacent from u. I If u = v , then e is called a loop. I The directed edges with the same initial point and same terminal point are said to be parallel. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Example: Draw the directed graph consists of: four vertices: V (G ) = {A, B, C , D} and seven edges: E (G ) = {e1, e2, ..., e7} = {(A, D), (B, A), (B, A), (D, B), (B, C ), (D, C ), (B, B)} Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Example: Draw the directed graph consists of: four vertices: V (G ) = {A, B, C , D} and seven edges: E (G ) = {e1, e2, ..., e7} = {(A, D), (B, A), (B, A), (D, B), (B, C ), (D, C ), (B, B)} I If the edges and/or vertices of a directed graph labeled with some kind of data, then the directed graph is called labeled directed graph. I Example: In class. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I I I Degrees Paths Suppose G is a directed graph. The outdegree of a vertex v of G , written outdeg(v ), is the number of edges beginning at v . And the indegree of v , written indeg(v ), is the number of edges ending at v . Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I I I I Degrees Paths Suppose G is a directed graph. The outdegree of a vertex v of G , written outdeg(v ), is the number of edges beginning at v . And the indegree of v , written indeg(v ), is the number of edges ending at v . Since each edge begins and ends at a vertex we have the following theorem: Theorem: The sum of the outdegrees of the vertices of a digraph G equals the sum of the indegrees of the vertices, which equals the number of edges in G. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I I I I I I Degrees Paths Suppose G is a directed graph. The outdegree of a vertex v of G , written outdeg(v ), is the number of edges beginning at v . And the indegree of v , written indeg(v ), is the number of edges ending at v . Since each edge begins and ends at a vertex we have the following theorem: Theorem: The sum of the outdegrees of the vertices of a digraph G equals the sum of the indegrees of the vertices, which equals the number of edges in G. A vertex v with zero indegree is called a source, and a vertex v with zero outdegree is called a sink. Example: In class. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Degrees Paths The concepts of path, simple path, trail, and cycle in directed graph are similar as in nondirected graphs except that the directions of the edges must agree with the direction of the path. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees Degrees Paths I The concepts of path, simple path, trail, and cycle in directed graph are similar as in nondirected graphs except that the directions of the edges must agree with the direction of the path. I A vertex v is reachable from a vertex u if there is a path from u to v . I If v is reachable from u, then there must be a simple path from u to v (just by eliminating redundant edges). Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I In class. Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I Example: Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I I We will use the term node, rather than vertex, with binary trees. A binary tree T is defined as a finite set of elements, called nodes, such that: 1. T is empty (called the null tree or empty tree), or 2. T contains a distinguished node R, called the root of T , and the remaining nodes of T form an ordered pair of disjoint binary trees T1 and T2 . Math 301 Directed Graph and Binary Trees Outline Introduction Directed Graph Basic Definitions Adjacency matrix and Linked Representation Binary Trees I I We will use the term node, rather than vertex, with binary trees. A binary tree T is defined as a finite set of elements, called nodes, such that: 1. T is empty (called the null tree or empty tree), or 2. T contains a distinguished node R, called the root of T , and the remaining nodes of T form an ordered pair of disjoint binary trees T1 and T2 . I I I I If T does contain a root R, then the two trees T1 and T2 are called, respectively, the left and right subtrees of R. If T1 is nonempty, then its root is called the left successor of R; If T2 is nonempty, then its root is called the right successor of R. A node with no successors is called a terminal node. Math 301 Directed Graph and Binary Trees