1 / 99

Trees

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

madra
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 • Implementation 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. BINARY TREES Binary Trees

  19. 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

  20. Binary Trees

  21. 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

  22. Examples of Binary Trees • Expression tree • Non-leaf (internal) nodes contain operators • Leaf nodes contain operands • Huffman tree • Represents Huffman codes for characters appearing in a file or stream • Huffman code may use different numbers of bits to encode different characters • ASCII or Unicode uses a fixed number of bits for each character Binary Trees

  23. Examples of Huffman Tree Code for b = 100000 Code for w = 110001 Code for s = 0011 Code for e = 010 Binary Trees

  24. Binary Trees

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

  26. Binary Trees

  27. Binary Trees

  28. Binary Trees

  29. Binary Trees

  30. Binary Trees

  31. Binary Trees

  32. Binary Trees

  33. 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? Binary Trees

  34. Binary Trees

  35. Binary Trees

  36. Binary Trees

  37. Tree Node Level and Path Length Binary Trees

  38. Depth Example Depth 0 (root) Depth 1 Depth 2 Depth 1 Binary Trees

  39. Binary Trees

  40. Binary Trees

  41. Binary Trees

  42. Binary Trees

  43. Binary Trees

  44. Binary Trees

  45. Binary Trees

  46. Binary Trees

  47. Binary Trees

  48. Binary Trees

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

  50. Binary Trees

More Related