Announcements HW2 available, due 02/05, 11:59p. MT1 2/4, 7-9p. - - PowerPoint PPT Presentation

announcements
SMART_READER_LITE
LIVE PREVIEW

Announcements HW2 available, due 02/05, 11:59p. MT1 2/4, 7-9p. - - PowerPoint PPT Presentation

Announcements HW2 available, due 02/05, 11:59p. MT1 2/4, 7-9p. Perfect Binary tree: Perfect tree of height h, P h : P -1 is an empty tree if h > -1, then P h is {r, T L , T R }, where T L and T R are P h-1 . P 0 : P 2 : P 1 : Check


slide-1
SLIDE 1

Announcements –

HW2 available, due 02/05, 11:59p. MT1 2/4, 7-9p. Perfect Binary tree:

Check for understanding: How many nodes in a perfect tree of height h? P0: P2: P1:

Perfect tree of height h, Ph:

  • P-1 is an empty tree
  • if h > -1, then Ph is {r, TL, TR}, where TL and TR are Ph-1.
slide-2
SLIDE 2

Complete Binary tree: for any level k in [0,h-1], level k has 2k nodes, and on level h,

all nodes are "pushed to the left." http://xlinux.nist.gov/dads//HTML/completeBinaryTree.html

Check for understanding:

Is every full tree complete? Is every complete tree full?

Complete tree of height h, Ch:

  • if h= -1, then Ch is {}
  • if h > -1, then Ch is {r, TL, TR}, and either:

TL is _______ and TR is ________ OR TL is _______ and TR is ________

I U L A P D N O H W E B

slide-3
SLIDE 3

Rooted, directed, ordered, binary trees

Tree ADT: insert remove traverse

1 2 3 4 5 6 7 8 9 10 11 12 13 template<class T> class tree { public: … private: struct Node { T data; Node * left; Node * left; }; Node * root; … };

slide-4
SLIDE 4

Theorem: Our implementation of an n item binary tree has ______ null pointers.

slide-5
SLIDE 5

Traversal…

slide-6
SLIDE 6

Traversals: A few discussion points…

Is preOrder public or private?

1 2 3 4 5 6 7 8 template<class T> void tree<T>::preOrder(Node * croot){ if (croot != NULL){ yell(croot->data); preOrder(croot->left); preOrder(croot->right); } }

slide-7
SLIDE 7

Traversal shortcuts…

slide-8
SLIDE 8

Traversal summary (applications next time)…

A traversal must visit every node Running time is O(n), where n is # of nodes in tree.