This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Handout #23 CS103 April 21, 2010 Robert Plummer Graphs and Trees More on Graphs We discussed graphs when we were studying relations. Here are some slightly different and extended definitions: Definition An undirected graph is an ordered pair (V, E) where (i) V is a nonempty set of vertices, and (ii) E is an edge set consisting of unordered pairs of distinct vertices. Unless we say otherwise, we will be talking about undirected graphs. (The reference for these definitions is: Introduction to Algorithms, 2 nd Ed. , Thomas Cormen, et al. This is a classic CS text that you will probably encounter in CS161.) Definitions If (u, v) is an edge, we say (u, v) is incident on vertices u and v, that u is adjacent to v, and that v is adjacent to u. The degree of a vertex is the number of edges incident on it. A path of length k from a vertex u to a vertex u' in a graph G = (V, E) is a sequence (v , v 1 , v 2 , ..., v k ) of vertices from V such that u = v , u' = v k , and (v i1 , v i ) ∈ E for i = 1, 2, ..., k. A path is simple if all its vertices are distinct. A path (v , v 1 , v 2 , ..., v k ) forms a (simple) cycle if k ≥ 3, v = v k , and v 1 , v 2 , ..., v k are distinct. A graph with no cycles is acyclic . A graph is connected if there is a path between every pair of vertices. 1 2 3 4 5 6 7 – 2 – Trees Definition A tree is an acyclic, connected, graph in which one vertex has been designated as the root (node 1 in the example below): We normally draw the root of a tree at the top, and we refer to the vertices as nodes . Here are some properties of trees: Let G = (V, E) be an undirected graph. The following statements are equivalent: 1. G is a tree. 2. Any two vertices of G are connected by a unique simple path. 3. G is connected, but if any edge in E is removed, the result is not connected. 4. G is connected, and E = V  1. 5. G is acyclic, and E = V  1. 6. G is acyclic, but if an edge is added to E, the resulting graph has a cycle. Definitions Consider a node x in a tree with root r. Any node on the unique path from r to x is an ancestor of x. If y is an ancestor of x, x is a descendant of y. If the last node on the path from r to x is (y, x), then y is the parent of x and x is the child of y. The number of children of a node is called the degree of the node. Nodes with the same parent are siblings . A node with no children is a leaf , and a node that is not a leaf is an interior nod e. The length of the path from the root to a node is the depth (or level ) of the node, and the length of the longest path from the root to a leaf is the height of the tree. 1 2 3 4 5 6 7 – 3 – Definitions The subtree rooted at x is the tree consisting of x, its descendants, and the edges connecting them....
View
Full
Document
This document was uploaded on 02/08/2011.
 Fall '09

Click to edit the document details