Trees
Day 1
,
Day 2
Introduction
•
So far, all data structures have been "linear": items follow one after another
•
Next comes trees: number of items following another item may vary
•
Advantages: Insert/delete are fast; find is fast (usually)
Tree Basics
•
What is a tree? Consider the following example:
Terms
•
Node: data (the value we actually care about) and key (the value used to find the data), plus
branches to other nodes. All of the above circles are considered to be
nodes
of the tree
•
Edges: The "branches" mentioned above. An edge is each line drawn in the image. The
branches are usually considered to be directional: if you have an edge from A to D, you are not
allowed to follow the edge back from D to A.
•
Each branch leads to a
child
. B  N are all children of some kind.
•
All of the fellow children are known as
siblings
. B, C, and D are all siblings.
•
All siblings have a common
parent
. However, a child is usually not aware of its parent:
instead, parents keep track of only their parents. B, C, and D all have the common parent, A. A
node is only allowed to have one parent.
•
There is a special node which has no parent: the
root
. Above, A is the root node.
•
The number of children a node has is the the
degree
. A and J are of degree 3; K is of degree 0:
it has no children.
•
Some nodes have no children: these are known as
leafs
. E, G, K, L, M, and N are all leafs.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 MarvinSolomon
 Data Structures, leaf node

Click to edit the document details