The Tree Data Structure: ECE 250 Algorithms and Data Structures
The Tree Data Structure: ECE 250 Algorithms and Data Structures
Outline
2
Tree Data Structure
Trees
3
Tree Data Structure
Trees
4
Tree Data Structure
Linked List
5
Tree Data Structure
Trees
6
Tree Data Structure
Terminology
• The shape of a tree gives a natural flow from the root node, or just root
7
Tree Data Structure
Terminology
8
Tree Data Structure
Terminology
9
Tree Data Structure
Terminology
10
Tree Data Structure
Terminology
are equal if the order of the children is ignored (an unordered tree)
• They are different if order is relevant (ordered trees)
– We will usually examine ordered trees (linear orders)
– In a hierarchical ordering, order is not relevant
11
Tree Data Structure
Terminology
12
Tree Data Structure
Terminology
• For each node in a tree, there exists a unique path from the root node to
that node
• The length of this path is the depth of the node, e.g.,
– E has depth 2
– L has depth 3
13
Tree Data Structure
Terminology
• The height of a tree is defined as the maximum depth of any node within the
tree
• The height of a tree with one node is 0
– Just a root
• For convenience, we define the height of the empty tree to be –1
14
Tree Data Structure
Terminology
15
Tree Data Structure
Terminology
16
Tree Data Structure
Terminology
17
Tree Data Structure
18
Tree Data Structure
19
Tree Data Structure
paragraph
20
Tree Data Structure
21
Tree Data Structure
22
Tree Data Structure
23
Tree Data Structure
24
Tree Data Structure
• Cascading Style Sheets (CSS) make use of this tree structure to describe
how HTML should be displayed
• For example:
<style type="text/css">
h1 { color:blue; }
</style>
indicates all text/decorations descendant from an h1 header should be blue
25
Tree Data Structure
26
Tree Data Structure
27
Tree Data Structure
28
Tree Data Structure
<style type="text/css">
h1 { color:blue; }
p u { color:red; }
</style>
29
Tree Data Structure
<style type="text/css">
h1 { color:blue; }
p u { color:red; }
</style>
30
Tree Data Structure
Example: XML
31
Tree Data Structure
MathML: x2 + y2 = z2
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics>
<mrow><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo>
<msup><mi>y</mi><mn>2</mn></msup></mrow>
<mo>=</mo><msup><mi>z</mi><mn>2</mn></msup></mrow>
<annotation-xml encoding="MathML-Content">
<apply><eq/>
<apply><plus/>
<apply><power/><ci>x</ci><cn>2</cn></apply>
<apply><power/><ci>y</ci><cn>2</cn></apply>
</apply>
<apply><power/><ci>z</ci><cn>2</cn></apply>
</apply>
</annotation-xml>
<annotation encoding="Maple">x^2+y^2 = z^2</annotation>
</semantics>
</math>
32
Tree Data Structure
MathML: x2 + y2 = z2
33
Tree Data Structure
XML
34
Tree Data Structure
Summary
35
Tree Data Structure
References
[1] Donald E. Knuth, The Art of Computer Programming, Volume 1: Fundamental Algorithms, 3rd
Ed., Addison Wesley, 1997, §2.2.1, p.238.
36
Tree Data Structure
Usage Notes
• These slides are made publicly available on the web for anyone to use
• If you choose to use them, or a part thereof, for a course at another institution, I ask only three
things:
– that you inform me that you are using the slides,
– that you acknowledge my work, and
– that you alert me of any mistakes which I made or changes which you make, and allow me the option of
incorporating such changes (with an acknowledgment) in my set of slides
Sincerely,
Douglas Wilhelm Harder, MMath
[email protected]
37