trees
play

Trees 5 May 2016 OSU CSE 1 A New Math Type: tree A ubiquitous - PowerPoint PPT Presentation

Trees 5 May 2016 OSU CSE 1 A New Math Type: tree A ubiquitous concept in computing is that of a tree Often we are interested in a binary tree , a special case of a tree in which each node has at most two children An informal


  1. Trees 5 May 2016 OSU CSE 1

  2. A New Math Type: tree • A ubiquitous concept in computing is that of a tree – Often we are interested in a binary tree , a special case of a tree in which each node has at most two children • An informal introduction (“node”?, “children”?) follows, using pictures rather than any new mathematical notation 5 May 2016 OSU CSE 2

  3. Recursive Structure • A tree is made up of: – A root node – A string of zero or more child nodes of the root, each of which is the root of its own tree • Since a tree may contain other trees, its structure is recursive • Note: the following explanation of trees is adequate for present purposes but is not technically complete; details later… 5 May 2016 OSU CSE 3

  4. B K R S A C L H E P T G 5 May 2016 OSU CSE 4

  5. Nodes B ? K R S A C L H E P T G 5 May 2016 OSU CSE 5

  6. Edges or B Branches K R S A C L H E P T G 5 May 2016 OSU CSE 6

  7. B root node (node B) K R S A C L H E P T G 5 May 2016 OSU CSE 7

  8. children of B root node (or, of node B) K R S A C L H E P T G 5 May 2016 OSU CSE 8

  9. parent of B node S (for example) K R S A C L H E P T G 5 May 2016 OSU CSE 9

  10. B siblings of node S K R S A C L H E P T G 5 May 2016 OSU CSE 10

  11. B K R S A C L H E P T G leaf nodes 5 May 2016 OSU CSE 11

  12. Yes, it’s B drawn root upside down! K R S A C L H E P leaf T G 5 May 2016 OSU CSE 12

  13. size of a tree B is its total number of nodes; here, it is 12 K R S A C L H E P T G 5 May 2016 OSU CSE 13

  14. Your Turn! What’s the size of each of these 4 trees? C Q R A Y W G C L K P H D T B 5 May 2016 OSU CSE 14

  15. path from B node B to node L; its length is 3 K R S A C L H E P T G 5 May 2016 OSU CSE 15

  16. height of a tree is the B length of the longest path from its root; here, it is 4 K R S A C L H E P T G 5 May 2016 OSU CSE 16

  17. Your Turn! What’s the height of each of these 4 trees? C Q R A Y W G C L K P H D T B 5 May 2016 OSU CSE 17

  18. A Tricky One? What’s the height of this D tree? Y L K A N P Q B 5 May 2016 OSU CSE 18

  19. B tree rooted at node B K R S A C L H E P T G 5 May 2016 OSU CSE 19

  20. subtree 0 of tree B rooted at node B (or, of node B) K R S A C L H E P T G 5 May 2016 OSU CSE 20

  21. subtree 1 of tree B rooted at node B (or, of node B) K R S A C L H E P T G 5 May 2016 OSU CSE 21

  22. subtree 2 of tree B rooted at node B (or, of node B) K R S A C L H E P T G 5 May 2016 OSU CSE 22

  23. Notice the recursive B structure: a root plus its subtrees. K R S A C L H E P T G 5 May 2016 OSU CSE 23

  24. Resources • Wikipedia: Tree structure – http://en.wikipedia.org/wiki/Tree_structure 5 May 2016 OSU CSE 24

Recommend


More recommend