Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 17 Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.

Similar presentations


Presentation on theme: "Lecture 17 Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine."— Presentation transcript:

1 Lecture 17 Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine

2 CSCI 1900 Lecture 17 - 2 Lecture Introduction Reading –Rosen Sections 11.1, 11.2 Review Graphs Trees Rooted Trees Specialized Trees

3 CSCI 1900 Lecture 17 - 3 Review of Directed Graphs A Digraph, G=(V, A), consists of a finite set V of objects called vertices, and a finite set A of objects called arcs between the vertices Arcs have a direction Example: V={1, 2, 3} A= { (1, 2), (3, 2) } 1 2 3

4 CSCI 1900 Lecture 17 - 4 Graphs A graph, G=(V, E), consists of a finite set V of objects called vertices, and a finite set E of objects called edges Edges have no direction Example: V={1,2,3} E= { (1,2), (2,3) } 1 2 3

5 CSCI 1900 Lecture 17 - 5 Connected Graph A graph is connected if there is a path (sequence of edges) between any two pairs of vertices Connected Disconnected

6 CSCI 1900 Lecture 17 - 6 Cycle C3C3 C4C4 If you can start at a node and move along edges and come back to the same node the graph has a cycle

7 CSCI 1900 Lecture 17 - 7 Acyclic Graphs A disconnected acyclic graph Not an acyclic graph A graph is acyclic if it has no cycles

8 CSCI 1900 Lecture 17 - 8 Trees Let A be a set and let T be a relation on A. We say that T is a tree if there is a vertex v 0 with the property that there exists a unique path in T from v 0 to every other vertex in A, but no path from v 0 to v 0 -Kolman, Busby, and Ross, p. 271 Or A tree is a connected acyclic graph

9 CSCI 1900 Lecture 17 - 9 Rooted Trees In computer science, we work primarily with rooted trees A rooted tree is a directed graph –Which has one vertex, v 0, called the root, with no arcs coming into it In-degree of v 0 = 0 –Any other vertex, v i, in the tree has exactly one path to it from v 0 In-degree of v i = 1 –There may be any number of paths from any vertex

10 CSCI 1900 Lecture 17 - 10 Examples of Trees From this point forward, we will follow the computer science conventions –Tree means rooted tree –Edge means directed edge Using the definitions given, determine which of the following examples are trees and which are not

11 CSCI 1900 Lecture 17 - 11 Is this a tree?

12 CSCI 1900 Lecture 17 - 12 Is this a tree?

13 CSCI 1900 Lecture 17 - 13 Is this a tree? CSCI 2910 Client & Server Side Prog CSCI 2800 Visual Prog Adv Concepts CSCI 1100 Using Info Technology CSCI 1710 WWW Design CSCI 1510 Student in University CSCI 1800 Visual Prog I CSCI 2150 Computer Organization CSCI 2235 Intro to Unix CSCI 3220 Intro to Database CSCI 3250 Software Engineering I CSCI 3350 Software Engineering II CSCI 4217 Ethical Issues CSCI 4800 Senior Capstone Technology CSCI 4227 Advanced Database CSCI 3400 Network Fundamentals CSCI 4417 System Administration

14 CSCI 1900 Lecture 17 - 14 Definitions Level – all of the vertices located n-edges from v 0 are said to be at level n Level 0 Level 1 Level 2 Level 3

15 CSCI 1900 Lecture 17 - 15 More Definitions A vertex, v, is considered the parent of all of the vertices connected to it by edges leaving v A vertex, v, is considered the child of the vertex connected to the single edge entering v A vertex, v, is considered the sibling of all vertices at the same level with the same parent

16 CSCI 1900 Lecture 17 - 16 More Definitions A vertex v j is considered a descendant of a vertex v i if there is a path from v i to v j The height of a tree is the number of the largest level The vertices of a tree that have no children are called leaves

17 CSCI 1900 Lecture 17 - 17 Tree Example Level 0 Level 1 Level 2 v2v2 v1v1 v5v5 v3v3 v4v4 v0v0 v6v6 v7v7 v8v8 v 0 is the parent of v 1, v 2, v 3, and v 4 v 1, v 2, v 3, and v 4 are children of v 0 v 1, v 2, v 3, and v 4 are siblings v 5, v 6, v 2, v 7, v 8, and v 4 are leaves (no children) Height of the tree is 2

18 CSCI 1900 Lecture 17 - 18 More Definitions If every vertex of a tree has at most n children, then the tree is considered an n-tree If every vertex of a tree with offspring has exactly n offspring, then the tree is considered a complete n-tree When n=2, the tree is a binary tree

19 CSCI 1900 Lecture 17 - 19 Examples 1.If the set A = {a, b, c, d, e} represents all of the vertices for a tree T, what is the maximum possible height of T? What is the minimum possible height of T? 2.If the set A = {a, b, c, d, e} represents all of the vertices for a tree T and T is a complete binary tree, what is the maximum height of T?

20 CSCI 1900 Lecture 17 - 20 Examples (cont) 3.If the height of a complete 4-tree is 3, how many leaves does this tree have?

21 CSCI 1900 Lecture 17 - 21 Key Concepts Summary Review Graphs Trees Rooted Trees Specialized Trees Reading for next time –Kolman Section 7.2, 7.3


Download ppt "Lecture 17 Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine."

Similar presentations


Ads by Google