1 / 20

Chapter 8

Chapter 8. Binary and Other Trees Part 2. The ADT BinaryTree. The Class BinaryTree. The Class BinaryTree (continue). The Class BinaryTree (continue). Root. MakeTree. BreakTree. PreOrder. InOrder. PostOrder. LevelOrder. An Application. ADT extensions.

fergal
Download Presentation

Chapter 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 8 Binary and Other Trees Part 2

  2. The ADT BinaryTree

  3. The Class BinaryTree

  4. The Class BinaryTree (continue)

  5. The Class BinaryTree (continue)

  6. Root

  7. MakeTree

  8. BreakTree

  9. PreOrder

  10. InOrder

  11. PostOrder

  12. LevelOrder

  13. An Application

  14. ADT extensions • PreOutput(): output the data fields in preorder • InOutput(): output the data fields in inorder • PostOutput(): output the data fields in postorder • LevelOutput(): output the data fields in level order • Delete(): delete a binary tree, freeing up its nodes • Height(): return the tree height • Size(): return the number of nodes in the tree

  15. OutputTime complexity: Θ(n) each static void Output(BinaryTreeNode<T> *t) {cout << t->data << ‘ ‘;} void PreOutput() {PreOrder(Output, root); cout << endl;} void InOutput() {InOrder(Output, root); cout << endl;} void PostOutput() {PostOrder(Output, root); cout << endl;} void LevelOutput() {LevelOrder(Output, root); cout << endl;}

  16. DeleteTime complexity: Θ(n) static void Free(BinaryTreeNode<T> *t) {delete t;} void Delete() {PostOrder(Free, root); root = 0;}

  17. Height • public: int Height() const {return Height(root);} • private: int Height(BinaryTreeNode<T> *t) const;

  18. HeightTime complexity: Θ(n)

  19. SizeTime complexity: Θ(n) • outside the class definition int _count; • public: int Size() {_count = 0; PreOrder(Addl, root); return _count;} • private: static void Addl(BinaryTreeNode *t) {_count++;}

  20. The End of Chapter 8 Part 2

More Related