1 / 88

Trees

Trees. Briana B. Morrison Adapted from Alan Eugenio. Topics. Trees Binary Trees Definitions (full, complete, etc.) Expression Trees Traversals. Tree Structures. Computers”R”Us. Sales. Manufacturing. R&D. US. International. Laptops. Desktops. Europe. Asia. Canada.

eunice
Télécharger la présentation

Trees

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. Trees Briana B. Morrison Adapted from Alan Eugenio

  2. Topics • Trees • Binary Trees • Definitions (full, complete, etc.) • Expression Trees • Traversals Binary Trees

  3. Tree Structures Binary Trees

  4. Computers”R”Us Sales Manufacturing R&D US International Laptops Desktops Europe Asia Canada What is a Tree • In computer science, a tree is an abstract model of a hierarchical structure • A tree consists of nodes with a parent-child relation • Applications: • Organization charts • File systems • Programming environments Binary Trees

  5. Binary Trees

  6. Terminology • First let’s learn some terminology about trees… Binary Trees

  7. Binary Trees

  8. Tree Structures Binary Trees

  9. Binary Trees

  10. Tree Structures Binary Trees

  11. Binary Trees

  12. Binary Trees

  13. Binary Trees

  14. Tree Structures Binary Trees

  15. Binary Trees

  16. Binary Trees

  17. 50, 80, 90, 84 Binary Trees

  18. A C D B E G H F K I J Tree Terminology • Root: node without parent (A) • Internal node: node with at least one child (A, B, C, F) • External node (a.k.a. leaf ): node without children (E, I, J, K, G, H, D) • Ancestors of a node: parent, grandparent, grand-grandparent, etc. • Depth of a node: number of ancestors • Height of a tree: maximum depth of any node (3) • Descendant of a node: child, grandchild, grand-grandchild, etc. • Subtree: tree consisting of a node and its descendants subtree Binary Trees

  19. BINARY TREES Binary Trees

  20. Binary Tree Definition • A binary tree T is a finite set of nodes with one of the following properties: • (a) T is a tree if the set of nodes is empty. (An empty tree is a tree.) • (b) The set consists of a root, R, and exactly two distinct binary trees, the left subtree TL and the right subtreeTR. The nodes in T consist of node R and all the nodes in TL and TR. Binary Trees

  21. Binary Trees

  22. Binary Tree • Applications: • arithmetic expressions • decision processes • searching • A binary tree is a tree with the following properties: • Each internal node has two children • The children of a node are an ordered pair • We call the children of an internal node left child and right child • Alternative recursive definition: a binary tree is either • a tree consisting of a single node, or • a tree whose root has an ordered pair of children, each of which is a binary tree A C B D E F G I H Binary Trees

  23. Binary Trees

  24. HOW CAN WE DEFINE leaves(t), THE NUMBER OF LEAVES IN THE BINARY TREE t? RECURSIVELY! Binary Trees

  25. Binary Trees

  26. Binary Trees

  27. Binary Trees

  28. Binary Trees

  29. Binary Trees

  30. Binary Trees

  31. height(t) = ? To distinguish the height of an empty tree from the height of a single-item tree, What should the height of an empty tree be? -1 Binary Trees

  32. Binary Trees

  33. Binary Trees

  34. Tree Node Level and Path Length Binary Trees

  35. Binary Trees

  36. Binary Trees

  37. Binary Trees

  38. Binary Trees

  39. Binary Trees

  40. Binary Trees

  41. Binary Trees

  42. Binary Trees

  43. Binary Trees

  44. Binary Trees

  45. Tree Node Level and Path Length – Depth Discussion Is this tree complete? Is it full? Binary Trees

  46. Binary Trees

  47. Tree Node Level and Path Length – Depth Discussion Is this tree complete? Is it full? What is its height? Binary Trees

  48. Tree Node Level and Path Length – Depth Discussion Is this tree complete? Is it full? What is its height? Binary Trees

  49. Binary Trees

  50. A B C D E R S F G L THIS ASSOCIATION SUGGESTS THAT A COMPLETE BINARY TREE CAN BE STORED IN AN ARRAY: Binary Trees

More Related