1 / 21

Lecture 17 Trees

Lecture 17 Trees. CSCI – 1900 Mathematics for Computer Science Spring 2014 Bill Pine. Lecture Introduction. Reading Kolman Section 7.1, 7.2 Review Graphs Trees Rooted Trees Specialized Trees. 3. 1. 2. Review of Directed Graphs.

melia
Download Presentation

Lecture 17 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. Lecture 17Trees CSCI – 1900 Mathematics for Computer Science Spring 2014 Bill Pine

  2. Lecture Introduction • Reading • Kolman Section 7.1, 7.2 • Review Graphs • Trees • Rooted Trees • Specialized Trees CSCI 1900

  3. 3 1 2 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) } CSCI 1900

  4. 3 1 2 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) } CSCI 1900

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

  6. C4 C3 Cycle • If you can start at a node and move along edges and come back to the same node the graph has a cycle CSCI 1900

  7. Not an acyclic graph A disconnected acyclic graph Acyclic Graphs • A graph is acyclic if it has no cycles CSCI 1900

  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 v0 with the property that there exists a unique path in T from v0 to every other vertex in A, but no path from v0 to v0 -Kolman, Busby, and Ross, p. 271 Or • A tree is a connected acyclic graph CSCI 1900

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

  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 CSCI 1900

  11. Is this a tree? CSCI 1900

  12. Is this a tree? CSCI 1900

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

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

  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 CSCI 1900

  16. More Definitions • A vertex vj is considered a descendant of a vertex vi if there is a path from vi to vj • The height of a tree is the number of the largest level • The vertices of a tree that have no children are called leaves CSCI 1900

  17. v0 v4 v1 v2 v3 v8 v5 v6 v7 Tree Example Level 0 • v0 is the parent of v1 , v2 , v3 , and v4 • v1 , v2 , v3 , and v4 are children of v0 • v1 , v2 , v3 , and v4 are siblings • v5 , v6 , v2 , v7 , v8 , and v4 are leaves (no children) • Height of the tree is 2 Level 1 Level 2 CSCI 1900

  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 CSCI 1900

  19. Examples • 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? • 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? CSCI 1900

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

  21. Key Concepts Summary • Review Graphs • Trees • Rooted Trees • Specialized Trees • Reading for next time • Kolman Section 7.2, 7.3 CSCI 1900

More Related