binary trees
play

Binary Trees Review From CSCI-1321 Data Abstractions CSCI-2320 - PowerPoint PPT Presentation

Binary Trees Review From CSCI-1321 Data Abstractions CSCI-2320 Dr. Tom Hicks Computer Science Department Root Root Node - A Node Without A Parent. Root Root 3 Leaf Leaf Node - A Node Without Children. Leaf Leaf 5 Ancestors {D,11} -


  1. Binary Trees Review From CSCI-1321 Data Abstractions CSCI-2320 Dr. Tom Hicks Computer Science Department

  2. Root Root Node - A Node Without A Parent. Root Root 3

  3. Leaf Leaf Node - A Node Without Children. Leaf Leaf 5

  4. Ancestors {D,11} - Nodes In The Path(s) To The Root. B, F  Ancestors Of D 5, 2, 1  Ancestors Of 11 7

  5. Descendants {B,6} - Nodes In The Path(s) To The Leaves. A,D,C,E  Descendants Of B 12,13,24,25,26,27  Descendants Of 6 9

  6. Skew Trees Skew Tree - A Tree With No More Than 1 Node At Each Level. Empty Tree A Skew Tree Has The Same Performance As A Linked List! 11

  7. Full/Perfect Binary Trees Full Tree - A Tree In Which The Lowest Level Is Fully Populated  Every Node, Other Than The Leaves, Has Two Children. Empty Tree Best Case Tree! Also Called A "Perfect" Tree 13

  8. Height Of Tree Height Of A Tree Is The Number Of Edges In The Longest Path From The Root To A Leaf Node Height Height = 5 15

  9. No Levels On A Tree Some Start With 0  Others With 1  WE ARE GOING TO USE 1 Level       1 Level      2 Height Level    3 Level   4 Level   5 Level          6 Height = 5 17

  10. Perfect/Full Trees  NL  No Levels - 1 Max Nodes  Perfect Tree  NL = 2 2 NL - 1 = 2 2 - 1 = 3 2 NL - 1 = 2 3 - 1 = 7 19

  11. Perfect/Full Trees  NL  No Levels - 2 Max Nodes  Perfect Tree  NL = 4 2 NL - 1 = 2 4 - 1 = 15 Height Of Perfect Binary Tree With 15 Nodes = Log 2 (15) = ~4 20

  12. Perfect/Full Trees  NL  No Levels - 3 Max Nodes  Perfect Tree  NL = 5 2 NL - 1 = 2 5 - 1 = 31 Height Of Perfect Binary Tree With 15 Nodes = Log 2 (31) = ~5 21

  13. Average Search = Total Searches / No Nodes Compute # Searches         1 1      4 2 2     3 3 3 9      12 4 4 4 ___ 26 26/9 = 2.89 23

  14. Balanced Binary Tree A Balanced Tree is one that cannot be expressed in fewer levels; it will have the lowest Average Search for that number of Nodes. 25

  15. Inorder Traversal Left  Root  Right  There Are Recursive & Non-Recursive Solutions! Preorder Traversal Root  Left  Right  There Are Recursive & Non-Recursive Solutions! Postorder Traversal Left  Right  Root  There Are Recursive & Non-Recursive Solutions! 26

  16. Recursive Solutions Are Quite Easy To Code Traverse The Left Visit The Root Traverse The Right 27

  17. Inorder Traversal D  B  H  E  I  A  F  C  G 28

  18. Inorder Traversal D  B  H  E  I  A  F  C  G H  D  I  B  J  E  K  A  L  F  C  G 29

  19. Preorder Traversal A  B  D  E  H  I  C  F  G A  B  D  H  I  E  J  K  C  F  L  G 30

  20. Postorder Traversal D  H  I  E  B  F  G  C  A H  I  D  J  K  E  B  L  F  G  C  A 31

  21. Data Abstractions CSCI 2320 Dr. Thomas E. Hicks Computer Science Department Trinity University Textbook: Introduction To Algorithms 3 rd Edition By Cormen, Leiserson, Rivest, Stein Textbook: A Tour Of C++ By Bjarne Stroustrup Special Thanks To For MIT Press & Adison Wesley For Content & Graphics That Are Relevant To This Presentation. 32

  22. Average Search = Total Searches / No Nodes 100 150 50 125 175 75 25 40 25 40 50 75 100 125 150 175

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