Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete...
-
date post
19-Dec-2015 -
Category
Documents
-
view
216 -
download
2
Transcript of Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete...
![Page 1: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/1.jpg)
Chapter 10 introduces trees. This presentation illustrates the
simplest kind of trees: Complete Binary Trees.
Complete Binary Trees
Data StructuresData Structuresand Other Objectsand Other ObjectsUsing C++Using C++
![Page 2: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/2.jpg)
Binary Trees
A binary tree has nodes, similar to nodes in a linked list structure.
Data of one sort or another may be stored at each node.
But it is the connections between the nodes which characterize a binary tree.
![Page 3: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/3.jpg)
Binary Trees
A binary tree has nodes, similar to nodes in a linked list structure.
Data of one sort or another may be stored at each node.
But it is the connections between the nodes which characterize a binary tree.
An example canillustrate how theconnections work
![Page 4: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/4.jpg)
A Binary Tree of States
In this example, the data contained at each node is one of the 50 states.
![Page 5: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/5.jpg)
A Binary Tree of States
Each tree has a special node called its root, usually drawn at the top.
![Page 6: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/6.jpg)
A Binary Tree of States
Each tree has a special node called its root, usually drawn at the top. The example tree
has Washingtonas its root.
![Page 7: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/7.jpg)
A Binary Tree of States
Each node is permitted to have two links to other nodes, called the left child and the right child.
![Page 8: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/8.jpg)
A Binary Tree of States
Each node is permitted to have two links to other nodes, called the left child and the right child.
![Page 9: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/9.jpg)
A Binary Tree of States
Children are usually drawn below a node.
The right child ofWashington is
Colorado.
The left child ofWashington is
Arkansas.
![Page 10: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/10.jpg)
A Binary Tree of States
Some nodes have only one child.
Arkansas has aleft child, but no
right child.
![Page 11: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/11.jpg)
A Quiz
Some nodes have only one child.
Which node has
only a right child?
![Page 12: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/12.jpg)
A Quiz
Some nodes have only one child.
Florida hasonly a right child.
![Page 13: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/13.jpg)
A Binary Tree of States
A node with no children is called a leaf.
![Page 14: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/14.jpg)
A Binary Tree of States
Each node is called the parent of its children.
Washington is theparent of Arkansas
and Colorado.
![Page 15: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/15.jpg)
A Binary Tree of States
Two rules about parents:
The root has no parent.
Every other node has exactly one parent.
![Page 16: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/16.jpg)
A Binary Tree of States
Two nodes with the same parent are called siblings.
Arkansasand Coloradoare siblings.
![Page 17: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/17.jpg)
Complete Binary Trees
A complete binary tree is a special kind of binary tree which will be useful to us.
![Page 18: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/18.jpg)
Complete Binary Trees
A complete binary tree is a special kind of binary tree which will be useful to us.
When a completebinary tree is built,
its first node must bethe root.
![Page 19: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/19.jpg)
Complete Binary Trees
The second node of a complete binary tree is always the left child of the root...
![Page 20: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/20.jpg)
Complete Binary Trees
The second node of a complete binary tree is always the left child of the root...
... and the third node is always the right child of the root.
![Page 21: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/21.jpg)
Complete Binary Trees
The next nodes must always fill the next level from left to right.
![Page 22: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/22.jpg)
Complete Binary Trees
The next nodes must always fill the next level from left to right.
![Page 23: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/23.jpg)
Complete Binary Trees
The next nodes must always fill the next level from left to right.
![Page 24: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/24.jpg)
Complete Binary Trees
The next nodes must always fill the next level from left to right.
![Page 25: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/25.jpg)
Complete Binary Trees
The next nodes must always fill the next level from left to right.
![Page 26: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/26.jpg)
Complete Binary Trees
The next nodes must always fill the next level from left to right.
![Page 27: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/27.jpg)
Is This Complete?
![Page 28: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/28.jpg)
Is This Complete?
![Page 29: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/29.jpg)
Is This Complete?
![Page 30: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/30.jpg)
Is This Complete?
![Page 31: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/31.jpg)
Is This Complete?
Yes! It is called the empty
tree, and it has no nodes, not even a root.
![Page 32: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/32.jpg)
Implementing a Complete Binary Tree
We will store the date from the nodes in a partially-filled array.
An array of dataWe don't care what's inthis part of the array.
An integer to keeptrack of how many nodes are in the tree
3
![Page 33: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/33.jpg)
Implementing a Complete Binary Tree
We will store the date from the nodes in a partially-filled array.
An array of dataWe don't care what's inthis part of the array.
An integer to keeptrack of how many nodes are in the tree
3
Read Section 10.2 tosee details of how
the entries are stored.
![Page 34: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/34.jpg)
Binary trees contain nodes. Each node may have a left child and a right child. If you start from any node and move upward, you
will eventually reach the root. Every node except the root has one parent. The
root has no parent. Complete binary trees require the nodes to fill in
each level from left-to-right before starting the next level.
Summary
![Page 35: Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Complete Binary Trees Data Structures.](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d405503460f94a19c3d/html5/thumbnails/35.jpg)
THE END
Presentation copyright 2004 Addison Wesley Longman,For use with Data Structures and Other Objects Using Javaby Michael Main.
Some artwork in the presentation is used with permission from Presentation Task Force(copyright New Vision Technologies Inc) and Corel Gallery Clipart Catalog (copyrightCorel Corporation, 3G Graphics Inc, Archive Arts, Cartesia Software, Image ClubGraphics Inc, One Mile Up Inc, TechPool Studios, Totem Graphics Inc).
Students and instructors who use Data Structures and Other Objects Using C++ are welcometo use this presentation however they see fit, so long as this copyright notice remainsintact.