Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science: A Structured Programming Approach Using C1 15-5 Trees Trees are used extensively in computer science to represent algebraic formulas;

Similar presentations


Presentation on theme: "Computer Science: A Structured Programming Approach Using C1 15-5 Trees Trees are used extensively in computer science to represent algebraic formulas;"— Presentation transcript:

1 Computer Science: A Structured Programming Approach Using C1 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. Basic Tree Concepts Terminology Binary Trees Binary Search Trees Binary Tree Example Topics discussed in this section:

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

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

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

5 Computer Science: A Structured Programming Approach Using C5 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. Note

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

7 Computer Science: A Structured Programming Approach Using C7 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 Note

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Download ppt "Computer Science: A Structured Programming Approach Using C1 15-5 Trees Trees are used extensively in computer science to represent algebraic formulas;"

Similar presentations


Ads by Google