announcements
play

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


  1. 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 for understanding: How many nodes in a perfect tree of height h?

  2. Complete Binary tree: for any level k in [0,h-1], level k has 2 k nodes, and on level h, all nodes are "pushed to the left." Complete tree of height h, C h : • if h= -1, then C h is {} B • if h > -1, then C h is {r, T L , T R }, and either: U I T L is _______ and T R is ________ L D H E OR A P N O W T L is _______ and T R is ________ http://xlinux.nist.gov/dads//HTML/completeBinaryTree.html Check for understanding: Is every full tree complete? Is every complete tree full?

  3. Rooted, directed, ordered, binary trees 1 template<class T> 2 class tree { 3 public: 4 … 5 private: Tree ADT: 6 struct Node { 7 T data; 8 Node * left; insert 9 Node * left; 10 }; remove 11 Node * root; 12 … traverse 13 };

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

  5. Traversal…

  6. Traversals: A few discussion points… template<class T> 1 void tree<T>::preOrder(Node * croot){ 2 3 if (croot != NULL){ yell(croot->data); 4 preOrder(croot->left); 5 preOrder(croot->right); 6 7 } } 8 Is preOrder public or private?

  7. Traversal shortcuts…

  8. Traversal summary (applications next time)… A traversal must visit every node Running time is O(n), where n is # of nodes in tree.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend