Download presentation

Presentation is loading. Please wait.

Published byLewis McBride Modified over 4 years ago

1
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University

2
Outline Graph-Tree –Basic Definition –Rooted Trees –Applications of Trees –Game Tree

9
Basic Definition Tree –a connected graph with no simple circuits –No multiple edges or loops Theorems –a graph is a tree iff a unique simple path between any two of its vertices –A tree with n vertices has n – 1 edges Forest

12
Rooted Tree Is a directed graph T satisfying –It is a tree when the directions of the edges are ignored. –There is a unique vertex r (called the root) such that the indegree of r is 0 and the indegree of any other vertex is 1. Examples: family tree, position tree Terminology: parent, child, terminal vertex, internal vertex, subtree, ancestor, descendant An m-ary tree, A full m-ary tree, A balanced m- ary tree with height h

13
Order Rooted Tree Is a rooted tree where the children of each internal vertex are ordered. ordered binary tree: two child, left/right

17
Tree Traversal Is a procedure that systematically visits every vertex of an ordered rooted tree Three most commonly used algorithms –Preorder traversal. –Inorder traversal. –Postorder traversal.

20
Example#1 List three kinds of traversals.

21
Binary Search Trees Is a binary tree in which each vertex is labeled with a key such that –No two vertices have the same key –If vertex u belongs to the left subtree of vertex v, then u v –If vertex w belongs to the right subtree of vertex v, then v w construction algorithm

23
S=1+2+2 2 +2 3 +s 4 + …… +2 62 +2 63 2S=2+2 2 +2 3 +2 4 + …… +2 62 +2 63 +2 64 2S-S=S=2 64 -1 2 64 =2 4 ×2 60 = 16×10 18 150 years to get this produce

24
Carl Sagan (1934-1996.12.20) A Pale Blue Planet Mourns the Passing of a Passionate Scientist A Pale Blue Planet Mourns the Passing of a Passionate Scientist

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google