Thinking in Pictures
Graphs
Let S be a set and R: S x S be a relation on S.
The graph G = (S,R) is a picture of the relation.
Example: X = {a,b}, S = powerset(X), R = {[x,y] | x is a proper subset of y}
Each member of S is a node in the graph, represented by a dot.
Each member of R is an arc (or an edge), represented by an arrow.
An arrow, x -> y, represents an element [x,y] in R:
y is called the head of the arrow (as in arrowhead)
and x is called the tail of the arrow
In our example, one of the edges (arcs) is the arrow {} -> {a}
The types of graphs that we will be be using are
directed graphs .
We can identify a graph as
being a directed graph
because the arcs are arrows , and not just
lines ; directed means that we have to follow the directions
of the arrows .
Definitions
- An initial node is a node we leave when traversing the arc.
- A terminal node is a node we arrive at when traversing the arc.
- The in-degree of a node n is the # arcs whose heads point to
node n
-
The out-degree of a node n is the # arcs whose tails start at
node n
- A path is a sequence of edges
[x_1,y_1], [x_2,y_2], ..., [x_n,y_n]
such that for 1 < i <= n : y_i-1 = x_i
Ex: [{},{a}],[{a},{ab}] is a path
- A cycle is a path such that x_1 = y_n (also called a circuit)
A cycle is called simple if it does not contain a cyclic subpath.
- A graph is called acyclic if it has no cycles
- A labelled directed graph is a directed graph in which each
arc is assigned a label or a value.
Ex: Airline fares from point A to point B: Not only is this a relation, but
we can assign an airfare for each "leg" of the flight. Notice, then, that
A->B and B->A can be two arcs with different air fares (labels).
Trees
A tree is a directed graph which:
- has no (directed) cycles, i.e., it is acyclic.
- has one single node, called the root of
the tree, which has in-degree 0
- all other nodes have in-degree 1
- there is a path from the root to every node
Other properties of a tree:
- The path from the root to a given node is unique
- The #arcs = #nodes-1
(Hmmm,
This seems like something we could prove using Induction!!)
- The subset of nodes that have out-degree 0 are called the leaf nodes.
Basic Tree Anatomy:
We always draw a tree upside down , with the root at the top
of the picture, so we don't need the arrowheads.
Proving Properties of Trees
In order to prove properties about trees, we need to focus on what they
are composed of: nodes and edges. Since we can count the nodes
and edges (add them up), the number of nodes and/or edges is a Natural
Number! So, it seems you are forever doomed to proving properties of trees
using Mathematical Induction. (Sigh!)
To prove properties about trees (like #2 in the "Other properties..." above,
we need a Recursive Definition of a Tree.
In Computer Science, Binary Trees are typically the ones we prove
properties about, because they are the most prevalent structures, both
theoretically and in practice (searching and sorting algorithms).
(Recursive) Definition: Binary Tree
A Binary Tree is a set of nodes T, such that either:
- (Basis) T is empty
- (Recursion) T contains a distinguished node r,
called the root of T, and the other nodes
(T-{r}) are divided into
two disjoint sets, called the left subtree of
r and the right subtree of r ,
each of which in itself is a Binary Tree.
More Tree definitions:
- Your book gives a more explicit definition of a tree, from that of a
graph, by explicitly naming the root r, of the tree: T=(S,A,r).
A is an adjacency relation, which says that for any
[x,y] in A it is said that x is
adjacent to y,
Adjacent to
means there is an
arc from x to y, i.e., x->y, in the tree.
- If x->y then y is child of x, and x is the parent of y.
- The depth of a node is defined recursively:
The depth of the root is zero; the depth of any other node is the depth of
it's parent plus 1.
- The height of a tree is the maximum of the depths of all nodes in
the tree.
- y is a descendent of x if there is a path from x to y.
x is an ancestor of y if there is a path from s to y.
Note: that descendent is the transitive of child
and ancestor the transitive of parent .
- We will assume that a tree is an ordered graph,
which means that the
children (or siblings) of a node have a left-to-right order.
- The frontier of a tree is an ordered list of leaf nodes, generated
from left to right.
- Given two nodes x and y, the minimal common ancestor of x and
y is a node z, where z is an ancestor of x and y, and z is also the ancestor
that is the closest ancestor to x and y.
©Elaine Wenderholm All Rights Reserved
Last modified: Thu Sep 17 10:56:20 EDT 1998