1 / 31

15-5 Trees

15-5 Trees. Trees are used extensively in computer science to represent algebraic formulas; as an efficient method for searching large, dynamic lists; and for such diverse applications as artificial intelligence systems and encoding algorithms. Topics discussed in this section:.

gartnerj
Download Presentation

15-5 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. 15-5 Trees Trees are used extensively in computer science to represent algebraic formulas; as an efficient method for searching large, dynamic lists; and for such diverse applications as artificial intelligence systems and encoding algorithms. Topics discussed in this section: Basic Tree Concepts Terminology Binary Trees Binary Search TreesBinary Tree Example Computer Science: A Structured Programming Approach Using C

  2. Note A tree consists of a finite set of elements, called nodes, and a finite set of directed lines, called branches, that connect the nodes. Computer Science: A Structured Programming Approach Using C

  3. FIGURE 15-30 Tree Computer Science: A Structured Programming Approach Using C

  4. FIGURE 15-31 Tree Nomenclature Computer Science: A Structured Programming Approach Using C

  5. Note The level of a node is its distance from the root. The height of a tree is the level of the leaf in the longest path from the root plus 1. Computer Science: A Structured Programming Approach Using C

  6. FIGURE 15-32 Subtrees Computer Science: A Structured Programming Approach Using C

  7. Note A tree is a set of nodes that either: 1. Is empty, or 2. Has a designated node, called the root, from which hierarchically descend zero or more subtrees, which are also trees Computer Science: A Structured Programming Approach Using C

  8. FIGURE 15-33 Collection of Binary Trees Computer Science: A Structured Programming Approach Using C

  9. FIGURE 15-34 Binary Tree Data Structure Computer Science: A Structured Programming Approach Using C

  10. FIGURE 15-35 Binary Tree Traversals Computer Science: A Structured Programming Approach Using C

  11. FIGURE 15-36 Binary Tree for Traversals Computer Science: A Structured Programming Approach Using C

  12. Note In the preorder traversal, the root is processed first,before its subtrees. Computer Science: A Structured Programming Approach Using C

  13. PROGRAM 15-19 Preorder Traversal of a Binary Tree Computer Science: A Structured Programming Approach Using C

  14. FIGURE 15-37Preorder Traversal—A B C D E F Computer Science: A Structured Programming Approach Using C

  15. FIGURE 15-38 Algorithmic Traversal of Binary Tree Computer Science: A Structured Programming Approach Using C

  16. PROGRAM 15-20 Inorder Traversal of a Binary Tree Computer Science: A Structured Programming Approach Using C

  17. FIGURE 15-39 Inorder Traversal—C B D A E F Computer Science: A Structured Programming Approach Using C

  18. Note In the inorder traversal, the root is processedbetween its subtrees. Computer Science: A Structured Programming Approach Using C

  19. Note In a binary search tree, the left subtree contains key values less than the root, and the right subtree containskey values greater than or equal to the root. Computer Science: A Structured Programming Approach Using C

  20. FIGURE 15-40 Binary Search Tree Computer Science: A Structured Programming Approach Using C

  21. FIGURE 15-41 Valid Binary Search Trees Computer Science: A Structured Programming Approach Using C

  22. FIGURE 15-42 Invalid Binary Search Trees Computer Science: A Structured Programming Approach Using C

  23. Note All BST insertions take place at a leaf or a leaflike node. Computer Science: A Structured Programming Approach Using C

  24. FIGURE 15-43 BST Insertion Computer Science: A Structured Programming Approach Using C

  25. PROGRAM 15-21 Binary Tree Insert Function Computer Science: A Structured Programming Approach Using C

  26. PROGRAM 15-21 Binary Tree Insert Function Computer Science: A Structured Programming Approach Using C

  27. FIGURE 15-44 Binary Tree Example Computer Science: A Structured Programming Approach Using C

  28. PROGRAM 15-22 Binary Tree Example Computer Science: A Structured Programming Approach Using C

  29. PROGRAM 15-22 Binary Tree Example Computer Science: A Structured Programming Approach Using C

  30. PROGRAM 15-22 Binary Tree Example Computer Science: A Structured Programming Approach Using C

  31. PROGRAM 15-22 Binary Tree Example Computer Science: A Structured Programming Approach Using C

More Related