Docsity

Spanning Trees: Finding and Understanding, Slides of Object Oriented Programming

Partial preview of the text

Download Spanning Trees: Finding and Understanding and more Slides Object Oriented Programming in PDF only on Docsity!

Spanning Trees, Intro. to Threads

A lecture with two distinct parts

  • Part I: Finishing our discussion of graphs
    • Today: Spanning trees
    • Definitions, algorithms (Primโ€™s, Kruskalโ€™s)
    • Travelling salesman problem
  • Part II: Introduction to the idea of threads
    • Why do we need them?
    • What is a thread?

Facts About Trees

  • |E| = |V| โ€“ 1
  • connected
  • no cycles

In fact, any two of

these properties

imply the third, and

imply that the graph

is a tree

Spanning Trees

A spanning tree of a connected undirected

graph (V,E) is a subgraph (V,E') that is a tree

Finding a Spanning Tree

A subtractive method

  • If there is a cycle, pick

an edge on the cycle,

throw it out โ€“ the

graph is still

connected (why?)

  • Repeat until no more

cycles

  • Start with the whole graph โ€“ it is connected
  • If there is a cycle, pick

an edge on the cycle,

throw it out โ€“ the

graph is still

connected (why?)

  • Repeat until no more

cycles

  • Start with the whole graph โ€“ it is connected

Finding a Spanning Tree

A subtractive method

An additive method

  • If more than one

connected component,

insert an edge between

them โ€“ still no cycles

(why?)

  • Repeat until only one

component

  • Start with no edges โ€“ there are no cycles

Finding a Spanning Tree

  • If more than one

connected component,

insert an edge between

them โ€“ still no cycles

(why?)

  • Repeat until only one

component

  • Start with no edges โ€“ there are no cycles

An additive method

Finding a Spanning Tree

  • If more than one

connected component,

insert an edge between

them โ€“ still no cycles

(why?)

  • Repeat until only one

component

  • Start with no edges โ€“ there are no cycles

An additive method

Finding a Spanning Tree

  • If more than one

connected component,

insert an edge between

them โ€“ still no cycles

(why?)

  • Repeat until only one

component

  • Start with no edges โ€“ there are no cycles

An additive method

Finding a Spanning Tree

Minimum Spanning Trees

  • Suppose edges are weighted, and we want a

spanning tree of minimum cost (sum of edge

weights)

  • Some graphs have exactly one minimum

spanning tree. Others have multiple trees with

the same cost, any of which is a minimum

spanning tree

Minimum Spanning Trees

  • Suppose edges are weighted, and we want a

spanning tree of minimum cost (sum of edge

weights)

  • Useful in network

routing & other

applications

  • For example, to

stream a video

3 Greedy Algorithms

A. Find a max weight edge โ€“ if it is on a cycle,

throw it out, otherwise keep it

3 Greedy Algorithms

A. Find a max weight edge โ€“ if it is on a cycle,

throw it out, otherwise keep it