Академический Документы
Профессиональный Документы
Культура Документы
Outline
Tree ADT
Binary Tree ADT
What is a Tree?
In computer science,
a tree is an abstract
model of a
hierarchical structure
A tree consists of
nodes with a parentchild relation
Applications:
Organization
charts
File systems
Computers R Us
Sales
US
Europe
Manufacturing
International
Asia
Laptops
Canada
Desktops
R&D
Tree Terminology
Root: node without a parent (A)
Internal node: node with at least one child (A, B, C,
F)
External node (a.k.a. leaf ): node without children
(E, I, J, K, G, H, D)
Parent node: node immediately above a given node
(parent of C is A)
Child node: node(s) immediately below a given
node (children of C are G and H)
Ancestors of a node: parent, grandparent, grandgrandparent, etc. (ancestors of G are C, A)
Depth of a node: number of ancestors (I has depth
3)
Height of a tree: maximum depth of any node (tree
with just a root has height 0, this tree has height 3)
Descendant of a node: child, grandchild, grandgrandchild, etc.
Subtree: tree consisting of a node and its
descendants
subtree
I
Binary Tree
In CS16, well be looking mainly at
binary trees
A binary tree is a tree with the
following property:
Perfection
A binary tree is a perfect binary tree if
Not perfect
Perfect!
Completeness
A binary tree is a left-complete binary tree if:
every level is completely full, possibly excluding the
lowest level
all nodes are as far left as possible
Left-complete!
Not left-complete