16
© 2010 Pearson Prentice Hall. All rights reserved. 1 §15.4, Trees

§15.4, Trees

  • Upload
    audra

  • View
    69

  • Download
    1

Embed Size (px)

DESCRIPTION

§15.4, Trees. Learning Targets Understand the definition and properties of a tree. Find a spanning tree for a connected graph. Find the minimum spanning tree for a weighted graph. Trees. A tree is a graph that is connected and has no circuits. All trees have the following properties: - PowerPoint PPT Presentation

Citation preview

Page 1: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 1

§15.4, Trees

Page 2: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 2

Learning Targets

1. Understand the definition and properties of a tree.2. Find a spanning tree for a connected graph.3. Find the minimum spanning tree for a weighted

graph.

Page 3: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 3

Trees

A tree is a graph that is connected and has no circuits. All trees have the following properties:

1. There is one and only one path joining any two vertices.

2. Every edge is a bridge.

3. A tree with n vertices must have n – 1 edges.

Page 4: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 4

Which of the following graphs are trees? Why or why not?

Example 1: Identifying Trees

Not a tree because it is disconnected, i.e., a tree with five vertices must have four edges.

A tree because it is connected, i.e., there is only one path joining any two vertices. If any edge is removed, then the graph would be disconnected.

Not a tree because it has a circuit, i.e., a tree with five vertices must have four edges and there are five vertices and five edges.

Page 5: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved.

Practice: Pg 857, #1 – 5

Page 6: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 6

Spanning Trees

• A subgraph is a set of vertices and edges chosen from among those of the original graph.

• A subgraph that contains all of a connected graph’s vertices, is connected, and contains no circuits is called a spanning tree.

• The two subgraphs in the previous example are spanning trees.

Page 7: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 7

Find a spanning tree for the graph.

Solution: A possible spanning tree must contain all eight vertices shown in the connected graph above. The spanning tree must have 8 – 1 = 7 edges.

• Since the previous graph has 12 edges, we must remove 5 edges.

Example 2: Finding a Spanning Tree

Page 8: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved.

We break the inner rectangular circuitremoving edge FG.

• We break the outer rectangularcircuit by removing all four of its edges while retaining the edges leading to vertices A, B, C, and D.

This leaves us the spanning tree seen on the right. Notice that each edge is a bridge and no circuits are present.

8

Example 2: Finding a Spanning Tree

Page 9: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved.

Practice: Pg 857, #17, 18

Page 10: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 10

Minimum Spanning Trees

• The minimum spanning tree for a weighted graph is a spanning tree with the smallest possible total weight.

From the spanning trees below, we see (c) has a smaller weight than (b), but is this the minimum spanning tree or should we continue to find other possible spanning trees that may have a total weight less than 107?

Page 11: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 11

Here is a procedure for finding the minimum spanning tree from a weighted graph:1. Find the edge with the smallest weight in the graph. If there is more than one, pick one at random. Mark it in red.2. Find the next-smallest edge in the graph. If there is more than one, pick one at random. Mark it in red.3. Find the next-smallest unmarked edge in the graph that does not create a red circuit. If there is more than one, pick one at random. Mark it in red.4. Repeat step 3 until all vertices have been included. The red edges are the desired minimum spanning tree.

Kruskal’s Algorithm

Page 12: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 12

Seven buildings on a college are connected by the sidewalks shown in the figure. The weighted graph represents buildings as vertices, sidewalks as edges, and sidewalk lengths as weights. A heavy snow has fallen and the sidewalks need to be cleared quickly. Campus decides to clear as little as possible and still ensure that students walking from building to building will be able to do so along cleared paths. Determine the shortest series of sidewalks to clear. What is the total length of the sidewalks that need to be cleared?

Example 3: Using Kruskal’s Algorithm

Page 13: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 13

Using Kruskal’s Algorithm, we complete minimizing the spanning tree in a series of steps given below. Refer to the next graph coinciding with the steps.

Example 3: Using Kruskal’s Algorithm

Page 14: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 14

Step 1. Find the edge with the smallest weight. Select edge GF by marking it in red.

Step 2. Find the next-smallest edgein the graph. Select BD by marking it in red.

Step 3. Find the next-smallest edgein the graph. Select AD by marking it in red.

Step 4. Find the next-smallest edgein the graph that does not create a circuit. Select DG, since it does not create a circuit, by marking it in red.

Example 3: Using Kruskal’s Algorithm

Page 15: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 15

Step 5. Find the next-smallest edge in thegraph that does not create a circuit. Select CD, since it does not createa circuit, by marking it in red.

Step 6. Find the next-smallest edgein the graph that does not create

a circuit. Select CE, since it doesnot create a circuit, by marking it in red.

The minimum spanning tree is completed. The red subgraph contains all seven vertices, six edges, and no circuits.

Example 3: Using Kruskal’s Algorithm

Page 16: §15.4, Trees

© 2010 Pearson Prentice Hall. All rights reserved. 16

The total length of the sidewalks that need to be cleared is 242 + 245 + 249 + 251 + 253 + 259,

or 1499 feet.

Example 3: Using Kruskal’s Algorithm

Homework: Pg 857, #6 – 16, 20 – 25.