15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

otherwise, i.e. the length of the longest path from a source of G to v. ( can be infinite)<br />

Definition 380 Given a digraph G = 〈V, E〉. The depth (dp(G)) of G is defined as<br />

sup{len(p) | p ∈ Π(G)}, i.e. the maximal path length in G.<br />

Example 381 The vertex 6 has depth two in the left graph and infine depth in the right<br />

one.<br />

1<br />

2<br />

3<br />

5<br />

4<br />

6 1<br />

The left graph has depth three (cf. node 1), the right one has infinite depth (cf. nodes 5 and<br />

6)<br />

c○: Michael Kohlhase 222<br />

We now come to a very important special class of graphs, called trees.<br />

Trees<br />

Definition 382 A tree is a directed acyclic graph G = 〈V, E〉 such that<br />

There is exactly one initial node vr ∈ V (called the root)<br />

All nodes but the root have in-degree 1.<br />

We call v the parent of w, iff 〈v, w〉 ∈ E (w is a child of v). We call a node v a leaf of G,<br />

iff it is terminal, i.e. if it does not have children.<br />

Example 383 A tree with root A and leaves D, E, F , H, and J.<br />

B<br />

A<br />

D E F<br />

F is a child of B and G is the parent of H and I.<br />

2<br />

3<br />

C<br />

G<br />

5<br />

4<br />

H I<br />

Lemma 384 For any node v ∈ V except the root vr, there is exactly one path p ∈ Π(G)<br />

with start(p) = vr and end(p) = v. (proof by induction on the number of nodes)<br />

c○: Michael Kohlhase 223<br />

In <strong>Computer</strong> <strong>Science</strong> trees are traditionally drawn upside-down with their root at the top, and<br />

the leaves at the bottom. The only reason for this is that (like in nature) trees grow from the root<br />

upwards and if we draw a tree it is convenient to start at the top of the page downwards, since we<br />

do not have to know the height of the picture in advance.<br />

Let us now look at a prominent example of a tree: the parse tree of a Boolean expression. Intuitively,<br />

this is the tree given by the brackets in a Boolean expression. Whenever we have an<br />

expression of the form A ◦ B, then we make a tree with root ◦ and two subtrees, which are<br />

constructed from A and B in the same manner.<br />

121<br />

J<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!