09 Trees - 9 - Trees Motivation Trees are a tool for...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Trees - 1 9 - Trees Motivation Trees are a tool for representing hierarchies of information. They find many uses in computing, and are especially relevant for understanding recursive programming, which is why we introduce them here. What are trees good for? 1. Hierarchy: world, countries, states, cities. 2. Ordering: binary search trees.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Trees - 2 3. Composition: arithmetic operations at branches, numbers at leaves. Definitions Node : A node is a particular location in the tree, like “USA” or “26” in the above examples. Root : The root is a distinguished node in a tree. In the trees above it is “World”, “47”, and “+”, respectively. Its tempting to call it the “base” of the tree (following the botanical trope that gives us the word “tree”) but unfortunately trees are often drawn “upside down” as in the examples above, with the root at the top. Child : A child of a node N is a node which is connected to N by a single link and further away from the root of the tree than N is. So the children of the node “26” are “15” and “33”. Parent : The parent of node N is the node which is both connected to N by a single link and closer to the root than N (there can be only one parent for a given node). So the parent of the node “Berkeley” in the first example above is “CA”. Notice that every node in a tree has one parent, except for the root, which has none. Leaf
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/12/2011 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 6

09 Trees - 9 - Trees Motivation Trees are a tool for...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online