An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

Similar documents
CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

CS 241 Analysis of Algorithms

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

COMP108 Algorithmic Foundations

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

CS 461, Lecture 17. Today s Outline. Example Run

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

Announcements. Not graphs. These are Graphs. Applications of Graphs. Graph Definitions. Graphs & Graph Algorithms. A6 released today: Risk

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

Constructive Geometric Constraint Solving

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

Section 10.4 Connectivity (up to paths and isomorphism, not including)

GREEDY TECHNIQUE. Greedy method vs. Dynamic programming method:

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

Minimum Spanning Trees

The University of Sydney MATH2969/2069. Graph Theory Tutorial 5 (Week 12) Solutions 2008

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

N=4 L=4. Our first non-linear data structure! A graph G consists of two sets G = {V, E} A set of V vertices, or nodes f

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

Planar Upward Drawings

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

Problem solving by search

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

Solutions for HW11. Exercise 34. (a) Use the recurrence relation t(g) = t(g e) + t(g/e) to count the number of spanning trees of v 1

1 Introduction to Modulo 7 Arithmetic

0.1. Exercise 1: the distances between four points in a graph

Trees as operads. Lecture A formalism of trees

Chapter 18. Minimum Spanning Trees Minimum Spanning Trees. a d. a d. a d. f c

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

Present state Next state Q + M N

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

COMPLEXITY OF COUNTING PLANAR TILINGS BY TWO BARS

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

ECE 407 Computer Aided Design for Electronic Systems. Circuit Modeling and Basic Graph Concepts/Algorithms. Instructor: Maria K. Michael.

Garnir Polynomial and their Properties

Similarity Search. The Binary Branch Distance. Nikolaus Augsten.

Lecture 20: Minimum Spanning Trees (CLRS 23)

10/30/12. Today. CS/ENGRD 2110 Object- Oriented Programming and Data Structures Fall 2012 Doug James. DFS algorithm. Reachability Algorithms

CS September 2018

Graph Contraction and Connectivity

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

12. Traffic engineering

Graph Theory. Vertices. Vertices are also known as nodes, points and (in social networks) as actors, agents or players.

Solutions to Homework 5

Scientific Programming. Graphs

NP-Completeness. CS3230 (Algorithm) Traveling Salesperson Problem. What s the Big Deal? Given a Problem. What s the Big Deal? What s the Big Deal?

Outline. Binary Tree

CMPS 2200 Fall Graphs. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

DUET WITH DIAMONDS COLOR SHIFTING BRACELET By Leslie Rogalski

Round 7: Graphs (part I)

QUESTIONS BEGIN HERE!

1. Determine whether or not the following binary relations are equivalence relations. Be sure to justify your answers.

(Minimum) Spanning Trees

Nefertiti. Echoes of. Regal components evoke visions of the past MULTIPLE STITCHES. designed by Helena Tang-Lim

QUESTIONS BEGIN HERE!

CMSC 451: Lecture 2 Graph Basics Thursday, Aug 31, 2017

CSI35 Chapter 11 Review

Computational Biology, Phylogenetic Trees. Consensus methods

Spanning Trees. BFS, DFS spanning tree Minimum spanning tree. March 28, 2018 Cinda Heeren / Geoffrey Tien 1

Seven-Segment Display Driver

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

Using the Printable Sticker Function. Using the Edit Screen. Computer. Tablet. ScanNCutCanvas

Register Allocation. Register Allocation. Principle Phases. Principle Phases. Example: Build. Spills 11/14/2012

A Simple Code Generator. Code generation Algorithm. Register and Address Descriptors. Example 3/31/2008. Code Generation

Chapter 9. Graphs. 9.1 Graphs

A 4-state solution to the Firing Squad Synchronization Problem based on hybrid rule 60 and 102 cellular automata

CS553 Lecture Register Allocation 1

Grade 7/8 Math Circles March 4/5, Graph Theory I- Solutions

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Module 2 Motion Instructions

Applications: The problem has several applications, for example, to compute periods of maximum net expenses for a design department.

Multipoint Alternate Marking method for passive and hybrid performance monitoring

RAM Model. I/O Model. Real Machine Example: Nehalem : Algorithms in the Real World 4/9/13

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

Organization. Dominators. Control-flow graphs 8/30/2010. Dominators, control-dependence. Dominator relation of CFGs

The Plan. Honey, I Shrunk the Data. Why Compress. Data Compression Concepts. Braille Example. Braille. x y xˆ

EE1000 Project 4 Digital Volt Meter

The University of Sydney MATH 2009

Improving Union. Implementation. Union-by-size Code. Union-by-Size Find Analysis. Path Compression! Improving Find find(e)

CIT 596 Theory of Computation 1. Graphs and Digraphs

CS 491 G Combinatorial Optimization

Transcription:

Unirt Grphs An unirt grph G = (V, E) V st o vrtis E st o unorr gs (v,w) whr v, w in V USE: to mol symmtri rltionships twn ntitis vrtis v n w r jnt i thr is n g (v,w) [or (w,v)] th g (v,w) is inint upon vrtis v n w n g my (v,w,) whr is ost omponnt (.g. istn) /0/0 DFR - DSA - Grphs

Exmpls /0/0 DFR - DSA - Grphs

Trminology PATH: squn o vrtis v, v, v n suh tht (v,v ), (v,v ), (v n-,v n ) r gs LENGTH: SIMPLE PATH: SIMPLE CYCLE: (unirt grph) numr o gs in pth (v nots pth lngth 0 rom v to v) ll vrtis r istint (xpt possily th irst n th lst) simpl pth o lngth or mor tht onnts vrtx to itsl /0/0 DFR - DSA - Grphs

Su-grph G = (V, E) su-grph o G is grph G = (V, E ) whr V is sust o V E onsists o gs (v,w) suh tht oth v n w r in V i E onsists o ll gs (v,w) in E suh tht oth v, w in V thn G is n INDUCED SUB-GRAPH o G onnt omponnt o grph G is mximl onnt inu su-grph tht is not itsl propr su-grph o ny othr onnt su-grph o G /0/0 DFR - DSA - Grphs

Su-grph: xmpl grph G su-grph G (n) inu su-grph On onnt omponnt - nmly G itsl /0/0 DFR - DSA - Grphs

An Unonnt Grph two onnt omponnts (h r tr) onnt yli grph is FREE TREE vry r tr with n >= vrtis ontins xtly (n-) gs ny g to r tr givs yl /0/0 DFR - DSA - Grphs

Grph Rprsnttion Ajny Mtrix Ajny List 0 0 0 0 0 0 0 0 /0/0 DFR - DSA - Grphs 7

Oprtions insrt rmov in vrtx g list oprtions nvigt is_pth is_yl shortst pth spnning orst /0/0 DFR - DSA - Grphs 8

Minimum-ost Spnning Trs G = (V,E) whr h g (v,w) hs n ssoit ost SPANNING TREE or G is r tr tht onnts ll th vrtis in G (n nos n (n-) gs; no yls) th ost o th spnning tr is th sum o th osts o th gs in th tr pplition rs: ommunition ntworks (trnsport/omputr) /0/0 DFR - DSA - Grphs 9

MST Proprty G = (V,E) onnt grph with ost untion on th gs lt U propr sust o V i (u,v) is n g o lowst ost suh tht u in U n v in V-U thn thr is MST tht inlus (u,v) s n g /0/0 DFR - DSA - Grphs 0

/0/0 DFR - DSA - Grphs Builing n MST: rtiv guss stp stp stp stp stp

Kruskl s prinipls Buil priority quu (PQ) with th gs, shortst gs irst Eh no in th grph oms omponnt Choos n g rom th PQ suh tht th g onnts istint omponnts until thr is only on omponnt this is th MST /0/0 DFR - DSA - Grphs

Kruskl s prinipls - xmpl PQ: ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ) Componnts: [], [], [], [], [], [] - omponnts ( ) [-], [], [], [], [] - omponnts ( ) [-], [], [-], [] - omponnts ( ) [-], [-], [, ] - omponnts ( ) [-, -, -], [-] - omponnts ( ) not hosn - & in sm omponnt ( ) [-, -, -, -, -] - omponnt (MST) /0/0 DFR - DSA - Grphs

MST xplntion (Kruskl) priority quu Commnts Th gs r stor in PQ (lowst vlus irst) Eh no oms omponnt Eh g shoul onnt omponnts NB: os not onnt omponnts n r in th sm omponnt (stp ov) ing woul lso rt yl An MST is r tr n thror hs no yls omplts th MST An MST with n nos hs (n-) gs An MST is Fr Tr (no yls) /0/0 DFR - DSA - Grphs

Kruskl s Algorithm (rtiv guss ) On mtho o onstruting n MST is Kruskl s strt with grph T = (V, ) i.. only th vrtis o G = (V, E) h vrtx is onnt omponnt (in th grph T) to onstrut th MST, T xmin th gs in E in orr o inrsing ost (implmnttion - priority quu) i th g onnts two vrtis in two onnt omponnts thn th g to T (othrwis isr th g) whn ll th gs r in on omponnt, T is MST or G /0/0 DFR - DSA - Grphs

Kruskl s Algorithm S = st o onnt omponnts (V rom G=(V,E)) mrg(a, B, S) -- mrg omponnts A & B in S - rnm A in(v, S) -- rturn nm o omponnt X in S : v in X initil( A, v, S) -- mk A th nm o omponnt in S ontining only vrtx v initilly insrt(, S) -- givn g to S rmov_pq() -- rmov n g rom th PQ (x, y, ) -- g (x, y) in PQ with ost /0/0 DFR - DSA - Grphs

Kruskl s Algorithm or h v in S initil ( nxt(nm), v, S) -- initilis whil (siz(s) > { -- siz = numr o omponnts gt_pq ( ); -- gt (x, y, ) rom PQ i ( in(x, S)!= in(y, S) ) { -- x, y in irnt omponnts mrg ( in (x, S), in (y, S), S ); insrt (gt_pq ( ), S); } rmov_pq( ); } /0/0 DFR - DSA - Grphs 7

Kruskl: xmpl PQ B E A C S D F /0/0 DFR - DSA - Grphs 8

Kruskl: xmpl PQ B E A C S D F B E A S D F /0/0 DFR - DSA - Grphs 9

Kruskl: xmpl PQ B E A C S D F B E A S D /0/0 DFR - DSA - Grphs 0

Kruskl: xmpl PQ B E A C S D F B A S D /0/0 DFR - DSA - Grphs

Kruskl: xmpl PQ B E A C S D F B A S /0/0 DFR - DSA - Grphs

Kruskl: xmpl PQ B E A C S D F B A S /0/0 DFR - DSA - Grphs

Kruskl: xmpl PQ B E A C S D F A S /0/0 DFR - DSA - Grphs

Kruskl: Commnt Using th PQ, th lgorithm is rsonly sy to unrstn in prinipl (th pitoril rprsnttion is sy to ollow) In gnrl it is worth looking t th prolm n its solution or going through ny lgorithm in til look t h lin o th psuo o n sur tht you n rlt th o to th tion rquir i.. tht you n intrprt th o /0/0 DFR - DSA - Grphs

/0/0 DFR - DSA - Grphs Builing n MST: rtiv guss stp stp stp stp stp

Prim s prinipls givn strt no x mrk s visit; not th g vlus rom x to th rmining nos; this uss rrys L or th g lngths n C or th no nm; in th shortst g rom x to y; mrk y s visit; uil COMPONENT (x y) i.. y is thn to th omponnt (i.. th visit nos); now xmin th g osts rom y to th rmining nos; i this g is hpr, rpl th urrnt g with this g. Th nw no is to th omponnt. Rpt or th unvisit nos. Th omponnt grows no y no n hpr gs rpl thos gs prviously oun s hpr. /0/0 DFR - DSA - Grphs 7

Prim s prinipls xmpl ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ) Strt no visit {} unvisit {,,,, } L = [,,,, ] C = [,,,, ] Shortst g ( ) visit {, } unvisit {,,, } ( ) is hpr L = [,,,, ] C = [,,,, ] ( ) not hpr no hng ( ) is hpr L = [,,,, ] C = [,,,, ] ( ) is hpr L = [,,,, ] C = [,,,, ] /0/0 DFR - DSA - Grphs 8

Prim s prinipls xmpl ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ) L = [,,,, ] C = [,,,, ] Shortst g ( ) visit {,, } unvisit {,, } ( ) not hpr no hng ( ) is hpr L = [,,,, ] C = [,,,, ] ( ) not hpr no hng Shortst g ( ) visit {,,, } unvisit {, } ( ) not hpr no hng ( ) not hpr no hng L = [,,,, ] C = [,,,, ] /0/0 DFR - DSA - Grphs 9

Prim s prinipls xmpl ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ), ( ) L = [,,,, ] C = [,,,, ] Shortst g ( ) visit {,,,, } unvisit {} ( ) is hpr L = [,,,, ] C = [,,,, ] Shortst g ( ) visit {,,,,, } unvisit {} mpty STOP Rsult L = [,,,, ] C = [,,,, ] /0/0 DFR - DSA - Grphs 0

Prim s prinipls - piturs L = [,,,, ] C = [,,,, ] L = [,,,, ] C = [,,,, ] /0/0 DFR - DSA - Grphs

Prim s prinipls - piturs L = [,,,, ] C = [,,,, ] L = [,,,, ] C = [,,,, ] /0/0 DFR - DSA - Grphs

Prim s prinipls - piturs L = [,,,, ] C = [,,,, ] L = [,,,, ] C = [,,,, ] /0/0 DFR - DSA - Grphs

Prim s prinipls - piturs L = [,,,, ] C = [,,,, ] L = [,,,, ] C = [,,,, ] /0/0 DFR - DSA - Grphs

MST xplntion (Prim) Prim s lgorithm is gry lgorithm gry = tks th lolly st solution Th MST grows th MST s on omponnt (similr to Dijkstr) Pross Choos th hpst g rom th omponnt to n unvisit no, g to th MST n mrk th no s visit (U) Strt t no hoos th hpst g mrk Now hoos th hpst g U = {,} mrk Now hoos th hpst g U = {,,} mrk Now hoos th hpst g U = {,,,} mrk Now hoos th hpst g U = {,,,,} mrk All nos hv now n visit U = {,,,,,} stop. /0/0 DFR - DSA - Grphs

Prim s Algorithm (rtiv guss ) V = {,,,, } initilis U to {} th spnning tr grows on g t tim h stp: in th shortst g (u,v) tht onnts U n V-U v to U until U = V i.. V-U = ost mtrix C givs th osts o h g /0/0 DFR - DSA - Grphs

Prim s Algorithm Prim ( no v) -- v is th strt no { U = {v}; or i in (V-U) { low-ost[i] = C[v,i]; losst[i] = v; } whil (!is_mpty (V-U) ) { -- in th losst vrtx in V-U i = irst(v-u); min = low-ost[i]; k = i; -- minimum ost g or j in (V-U-k) i (low-ost[j] < min) {min = low-ost[j]; k = j; } isply(k, losst[k]); -- isply g U = U + k; -- k to U or j in (V-U) i ( C[k,j] < low-ost[j] ) ) -- rjust osts {low-ost[j] = C[k,j]; losst[j] = k; } } } S http://www.s.ku.s/s/ution/ourss/vg0/rvision/inx.php?primex= /0/0 DFR - DSA - Grphs 7

/0/0 DFR - DSA - Grphs 8 Prim: xmpl ininity

Prim: xmpl Init: U V-U low-ost losst k / min {} {,,,,} (-,,,,, ) (-,,,,,) / isply ((,)) {,} {,,,} (-,,,,, ) (-,,,,,) / isply ((,)) {,,} {,,} (-,,,,, ) (-,,,,,) / isply ((,)) {,,,} {,} (-,,,,, ) (-,,,,,) / isply ((,)) {,,,,} {} (-,,,,, ) (-,,,,,) / isply ((,)) {,,,,,} { } (-,,,,, ) (-,,,,,) S http://www.s.ku.s/s/ution/ourss/vg0/rvision/inx.php?primex= /0/0 DFR - DSA - Grphs 9

Prim: Commnt Sin th MST is r tr, thr r n- gs, hn n- itrtions th ollowing o ins th lst ost g twn U n V-U (min, k) min = low-ost[i]; k = i; or j in (V-U-k) i (low-ost[j] < min) {min = low-ost[j]; k = j; } th ollowing o my rpl y or.g. A_MST(u,v) isply(k, losst[k]); -- isply g th r-justmnt o th osts is prhps th trikist to unrstn ut is in t similr to Dijkstr - ining th hpst (i,j) or (i,k) (k,j) or j in (V-U) i ( C[k,j] < low-ost[j] ) ) {low-ost[j] = C[k,j]; losst[j] = k; } /0/0 DFR - DSA - Grphs 0