Docsity

Notes on Spanning Trees, Prim's Algorithm - Discrete Structures | CSCI 243, Study notes of Discrete Structures and Graph Theory

Partial preview of the text

Download Notes on Spanning Trees, Prim's Algorithm - Discrete Structures | CSCI 243 and more Study notes Discrete Structures and Graph Theory in PDF only on Docsity!

10/30/

CSci 243

Discrete Structures

Lecture 23

Minimum Spanning Trees

10/30/

Outline^ • Spanning Trees• Application: Peer-to-Peer File Sharing• Minimum Spanning Trees: Prim & Kruskal• Project 2 Results• Test Topics

10/30/

Example

10/30/

Quick Question^ • Construct a spanning tree for this graph:

10/30/

Minimum Spanning Trees^ • Obviously, we could have minimized tree depth• For weighted graphs, we often want to minimize

total cost

Minimum spanning tree: A spanning tree for aconnected weighted graph which has thesmallest possible sum of weights of its edges

10/30/

Prim’s Algorithm^ tree

prim_mst(weighted

graph

G)

T^

=^

a^

minimum-weight

edge

and

its

vertices

for

i

to

n-

e^

=^

a^

minimum-weight

edge

incident

to

a

vertex

in

T

which

does

not

form

a

simple

circuit

in

T

if

added

to

T

T.add(e) } return

T

10/30/

Kruskal’s Algorithm^ tree

kruskal_mst(weighted

graph

G)

T^

=^

empty

graph

for

i

to

n-

e^

=^

a^

minimum-weight

edge

which

does

not

form

a^

simple

circuit

in

T

if

added

to

T

T.add(e) } return

T

10/30/

Example

10/30/

Project 2 Results^ • Average=50, Maximum=

Project

75 65 55 45 35 25 15 5 -

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

Grade

14

Class Grades

Before Test 2

390 370 350 330 310 290 270 250 230 210 190

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

Grade