This preview shows page 1. Sign up to view the full content.
Unformatted text preview: B B A F C E G subtree rooted at G CPSC 223
Fall 2010 15 Trees (Terminology)
In a “binary” tree, every node has at most 2 children More formally, T is a binary tree if – T has no nodes (is empty), or – T has the form r TL TR – where r is a node, and TL and TR are binary trees – TL is the left subtree of r and TR is the right subtree of r … note that this deﬁnition employs recursion! (this will be
helpful as we compute over trees) CPSC 223
Fall 2010 16 8 10/14/10 Trees (Terminology)
The “height” of a tree is the length of the longest path – The number of nodes that lie on the longest path from the
root to a leaf D the height of this tree is 3 B A F C E G CPSC 223
Fall 2010 17 Trees (Terminology)
An “empty” binary tree has no nodes D this is a not an empty binary tree B A CPSC 223
Fall 2010 F C E G 18 9 10/14/10 Trees (Terminology)
A “full” binary tree has a height h with no missing nodes – i.e., every internal node has exactly 2 children D this is a full binary tree B A F C E G CPSC 223
Fall 2010 19 Trees (Terminology)
A “complete” binary tree of height h is – a full binary tree at height h – 1, and – the nodes at height h are ﬁlled in from left to right … sometimes we say “level” h to mean the nodes at height h
D this is a complete binary tree B A CPSC 223
Fall 2010 F C E 20 10 10/14/10 Trees (Terminology)
A “balanced” binary tree has for every node – left and right subtrees that differ in height by at most 1
D B A this is not a balanced binary tree F D C E B this is a balanced binary tree A F C E E CPSC 223
Fall 2010 21 Binary Tree versus Binary Search Tree (BST)
• A Binary Search Tree stipulates where nodes are
placed in a Binary Tree … • In such a way as to maintain the items in sorted
order (based on a sort key) CPSC 223
Fall...
View
Full
Document
 Fall '10
 ShawnBowers
 Algorithms, Binary Search, Sort

Click to edit the document details