CS 225
Data Structures
Fe February 15 – Tr Tree Proof
Wa Wade Fa Fagen-Ul Ulmsch schnei eider er, , Cra Craig Zi Zilles
CS 225 Data Structures Fe February 15 Tr Tree Proof Wa Wade Fa - - PowerPoint PPT Presentation
CS 225 Data Structures Fe February 15 Tr Tree Proof Wa Wade Fa Fagen-Ul Ulmsch schnei eider er, , Cra Craig Zi Zilles Tree ee Ter erminology Find an edge that is not on the longest path in the tree. Give that edge a
Data Structures
Fe February 15 – Tr Tree Proof
Wa Wade Fa Fagen-Ul Ulmsch schnei eider er, , Cra Craig Zi Zilles
reasonable name.
b d g h j c e i f a
A binary tree T is either:
X S 2 C 2 5
height(T): length of the longest path from the root to a leaf Given a binary tree T: height(T) =
A X S 2 C 2 5
A tree F is full if and only if: 1. 2.
A X S 2 C 2 5
A perfect tree P is defined in terms of the tree’s height. Let Ph be a perfect tree of height h, and: 1. 2.
A X S 2 C 2 5
Conceptually: A perfect tree for every level except the last, where the last level if “pushed to the left”. Slightly more formal: For all levels k in [0, h-1], k has 2k nodes. For level h, all nodes are “pushed to the left”.
A X S 2 C 2 5 Y Z
A complete tree C of height h, Ch:
TL is __________ and TR is _________ OR TL is __________ and TR is _________
A X S 2 C 2 5 Y Z
Is every full tree complete? If every complete tree full?
A X S 2 C 2 5 Y Z
CS 225 has over 50 hours of open office hours each week, lots of time to get help!
CS 225 has over 50 hours of open office hours each week, lots of time to get help!
CS 225 has over 50 hours of open office hours each week, lots of time to get help!
case, or one exam question.
CS 225 has over 50 hours of open office hours each week, lots of time to get help!
yourself up for failure.
CS 225 has over 50 hours of open office hours each week, lots of time to get help!
insert, inserts an element to the tree. remove, removes an element from the tree. traverse,
#pragma once template <class T> class BinaryTree { public: /* ... */ private: };
BinaryTree.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
C S X A 2 2 5 Y
Ø Ø Ø Ø Ø Ø Ø Ø Ø
A X S 2 C 2 5 Y
C S X A 2 2 5 Y
Ø Ø Ø Ø Ø Ø Ø Ø Ø
Theorem: If there are n data items in our representation of a binary tree, then there are ___________ NULL pointers.
Base Cases: n = 0: n = 1: n = 2:
Induction Hypothesis:
Consider an arbitrary tree T containing n data elements: