CS 225
Data Structures
- Feb. 14 – Tre
rees
Wad ade Fag agen-Ulm lmschneid ider
CS 225 Data Structures Feb. 14 Tre rees Wad ade Fag agen-Ulm - - PowerPoint PPT Presentation
CS 225 Data Structures Feb. 14 Tre rees Wad ade Fag agen-Ulm lmschneid ider Lecture Resources Queue.h 4 template <class QE> 5 class Queue { 6 public: 7 class QueueIterator : public
Data Structures
rees
Wad ade Fag agen-Ulm lmschneid ider
template <class QE> class Queue { public:
class QueueIterator : public std::iterator<std::bidirectional_iterator_tag, QE> { public: QueueIterator(unsigned index); QueueIterator& operator++(); bool operator==(const QueueIterator &other); bool operator!=(const QueueIterator &other); QE& operator*(); QE* operator->(); private: int location_; };
/* ... */ private: QE* arr_; unsigned capacity_, count_, entry_, exit_; };
Queue.h
4 5 6
7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26
How does the Queue and the QueueIterator interact?
“The most important non-linear data structure in computer science.”
A tree is:
“Mario Family Line” <http://limitbreak.gameriot.com/blogs/ Caveat-Emptor/Mario-Family-Line>
We’ll focus on binary trees:
a path from the root
We’ll focus on binary trees:
graph
We’ll focus on binary trees:
allowed)?
reasonable name.
sibling.
allowed)?
reasonable name.
sibling.
allowed)?
reasonable name.
sibling.
allowed)?
reasonable name.
sibling.
allowed)?
reasonable name.
sibling.
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: 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 any level 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