Prim's MST Algorithm with step-by-step execution

Similar documents
Kruskal's MST Algorithm with step-by-step execution

CS 4407 Algorithms Greedy Algorithms and Minimum Spanning Trees

Minimum Spanning Tree Union-Find Data Structure. Feb 28, 2018 CSCI211 - Sprenkle. Comcast wants to lay cable in a neighborhood. Neighborhood Layout

Configuring MST (802.1s)/RSTP (802.1w) on Catalyst Series Switches Running CatOS

Review of Lab 9. Review Lab 9. Social Network Classes/Driver Data. Lab 10 Design

The Australian Society for Operations Research

Hat problem on a graph

Coalitional Game Theory

Network Indicators: a new generation of measures? Exploratory review and illustration based on ESS data

Estimating the Margin of Victory for Instant-Runoff Voting

Subreddit Recommendations within Reddit Communities

Chapter 8: Recursion

Do two parties represent the US? Clustering analysis of US public ideology survey

ForeScout Extended Module for McAfee epolicy Orchestrator

Online Ballots. Configuration and User Guide INTRODUCTION. Let Earnings Edge Assist You with Your Online Ballot CONTENTS

Troubleshooting Manual

The Effectiveness of Receipt-Based Attacks on ThreeBallot

NATIONAL MARINE ELECTRONICS ASSOCIATION INTERNATIONAL MARINE ELECTRONICS ASSOCIATION EFFECTIVE DATE AUGUST 1, 2012

Community Services Block Grant. T raining. ools for. nonprofit. governance. Tripartite Board Composition and Selection

The Civic Mission of MOOCs: Measuring Engagement across Political Differences in Forums

Michael Laver and Ernest Sergenti: Party Competition. An Agent-Based Model

Bank Reconciliation Script

BMI for everyone. Compsci 6/101: PFTW. Accumulating a value. How to solve an APT. Review how APTs and Python work, run

Parameterized Control Complexity in Bucklin Voting and in Fallback Voting 1

Networked Games: Coloring, Consensus and Voting. Prof. Michael Kearns Networked Life NETS 112 Fall 2013

Patterns in Congressional Earmarks

An Integrated Tag Recommendation Algorithm Towards Weibo User Profiling

User s Guide and Codebook for the ANES 2016 Time Series Voter Validation Supplemental Data

Designing a Social Network Prep for Lab 10. March 26, 2018 Sprenkle - CSCI Why classes and objects? How do we create new data types?

Warm Up: Identify the population and the sample: 1. A survey of 1353 American households found that 18% of the households own a computer.

Inviscid TotalABA Help

Article 12 Geographical Indications. Article 12.1 Protection of Geographical Indications

STUDY GUIDE FOR TEST 2

Release Notes Medtech Evolution ManageMyHealth

Andreas Fring. Basic Operations

PPIC Statewide Survey Methodology

Schedule Health Office Appointments

Introduction to the Third Amendment of the Trademark Law of China. August 30, 2013

SUMMARY OF FILING REQUIREMENTS FOR BRIEFS AND OTHER DOCUMENTS

Constraint satisfaction problems. Lirong Xia

Doctoral Research Agenda

Correlations PreK, Kindergarten, First Grade, and Second Grade

Municipal Code Online Inc. Software as a Service Agreement

Support Vector Machines

Estonian National Electoral Committee. E-Voting System. General Overview

HASHGRAPH CONSENSUS: DETAILED EXAMPLES

SCIMS UKBA processes

Positive Pay Reports and Reconciliation Guide. Transaction Reports

PRIVACY STATEMENT - TERMS & CONDITIONS. For users of Princh printing, copying and scanning services PRIVACY STATEMENT

Zaatari refugee camp. Account not required. Build skills in these areas: What you need:

PRESENTED BY: HOSTED BY: APPELLATE MOOT COURT COMPETITION 2011 COMPETITION RULES

Voting and Complexity

The Corn City State Bank Web Site is comprised of various Web pages operated by Corn City State Bank.

TERM OF USE AGREEMENT BETWEEN USER AND COUNTY OF BEDFORD

Comparison of the Psychometric Properties of Several Computer-Based Test Designs for. Credentialing Exams

Zaatari refugee camp. Account not required. Build skills in these areas: What you need:

AGREEMENT BETWEEN USER AND Fuller Avenue Church. The Fuller Avenue Church Web Site is comprised of various Web pages operated by Fuller Avenue Church.

NEUSE REGIONAL LIBRARY

Fall 2016 COP 3223H Program #5: Election Season Nears an End Due date: Please consult WebCourses for your section

EXAMINATION 3 VERSION B "Wage Structure, Mobility, and Discrimination" April 19, 2018

The Acerus Pharmaceuticals Corporation Web Site is comprised of various Web pages operated by Acerus Pharmaceuticals Corporation.

Terms of Use Call Today:

WESTLAW EDGE CHECKING CITATIONS IN KEYCITE QUICK REFERENCE GUIDE. Accessing KeyCite. Checking Cases and Administrative Decisions in KeyCite

Trademark Law of the People's Republic of China. Decision on Revising the Trademark Law of the People's Republic of China adopted at.

INSTRUCTION GUIDE FOR POLLING STATION MEMBERS ABROAD

Lab 11: Pair Programming. Review: Pair Programming Roles

Terms of Service and Use Agreement

UNITED STATES DISTRICT COURT NORTHERN DISTRICT OF GEORGIA ATLANTA DIVISION. v. 1:07-CV-2509-CAP ORDER

Check off these skills when you feel that you have mastered them. Identify if a dictator exists in a given weighted voting system.

Data manipulation in the Mexican Election? by Jorge A. López, Ph.D.

Safran North America UN/CEFACT XML Solutions

1 PEW RESEARCH CENTER

One View Watchlists Implementation Guide Release 9.2

Creating and Managing Clauses. Selectica, Inc. Selectica Contract Performance Management System

STATUTORY INSTRUMENTS. S.I. No.?????????? of 2016

ecourts Attorney User Guide

2016 Appointed Boards and Commissions Diversity Survey Report

Lab 3: Logistic regression models

Statistics, Politics, and Policy

autonomous agents Onn Shehory Sarit Kraus fshechory, Abstract

Random Forests. Gradient Boosting. and. Bagging and Boosting

How hard is it to control sequential elections via the agenda?

101 Ready-to-Use Excel Macros. by Michael Alexander and John Walkenbach

SCATTERGRAMS: ANSWERS AND DISCUSSION

Thinkwell s Homeschool Microeconomics Course Lesson Plan: 31 weeks

We should share our secrets

Conditions Governing Use of the Marks by VVA State Councils, Chapters, or Regions

DART-6UL EMC Radiation test

SOFTWARE END USER LICENSE AGREEMENT

Overview. Ø Neural Networks are considered black-box models Ø They are complex and do not provide much insight into variable relationships

Inviscid TotalABA Help

Political Districting for Elections to the German Bundestag: An Optimization-Based Multi-Stage Heuristic Respecting Administrative Boundaries

Cluster Analysis. (see also: Segmentation)

NOTE: ANY USAGE NOT COVERED IN THIS IDENTITY MANUAL MUST BE PRE-APPROVED BY THE KIRK HOUSE MANAGEMENT.

Care Management v2012 Enhancements. Lois Gillette Vice President, Care Management

Minnehaha County Election Review Committee

Morningstar ByAllAccounts Service User Agreement

US Code (Unofficial compilation from the Legal Information Institute)

PRESENTED BY: APPELLATE MOOT COURT COMPETITION 2013 RULES

Case 4:16-cv Document 11 Filed in TXSD on 08/15/16 Page 1 of 32 IN UNITED STATES DISTRICT COURT FOR THE SOUTHERN DISTRICT OF TEXAS

Transcription:

Prim's MST Algorithm with step-by-step execution Daniel Michel Tavera Student at National Autonomous University of Mexico (UNAM) Mexico e-mail: daniel_michel@ciencias.unam.mx Social service project director: Dr. Patricia Esperanza Balderas Cañas Full time professor at National Autonomous University of Mexico (UNAM) Mexico e-mail: balderas.patricia@gmail.com Introduction Prim's MST Algorithm is a well known solution to the Minimum Spanning Tree (MST) problem, which consists in finding a subset of the edges of a connected weighed graph, such that it satisfies two properties: it maintains connectivity, and the sum of the weights of the edges in the set is minimized. In this work we utilize the definition of Prim's MST algorithm given by Cook et. al. (see References) which is as follows: "Keep a tree H = (V(H),T) with V(H) initially {r} for some r 2 V, and T initially :. At each step add to T a least-cost edge e not in T such that H remains a tree. Stop when H is a spanning tree." This work is part of a social service project consisting in the implementation of several graph theory algorithms with step-by-step execution, intended to be used as a teaching aid in graph theory related courses. The usage examples presented were randomly generated. Module usage The PrimMST module contains only a single procedure definition for Prim(G, stepbystep, draw, initial), as follows: Calling Prim(...) will attempt to calculate the MST for graph G using Prim's Algorithm. The parameters taken by procedure Prim(...) are explained below: G is an object of type Graph from Maple's GraphTheory library, it is the graph for which the MST will be computed. Regardless of how it is defined, G will always be treated as though it is undirected. This parameter is not optional

stepbystep is a true/false value. When it is set to true, the procedure will print a message reporting whenever an edge is added to the MST or discarded because it would create a loop. When it is false, only the final result will be shown. This parameter is optional, and its default value is false. draw is a true/false value. When it is set to true, the resulting MST will be displayed after computation finishes; if both stepbystep and draw are true then the graph G will be drawn at every step, highlighting the edges in the MST in green and the discarded edges in red. When draw is set to false, the graphs will not be displayed, and the procedure will only print the total weight of the MST and return the edge list for the MST. This parameter is optional, and its default value is true. initial is a symbol representing the vertex of G from which the algorithm will begin construction of the MST. If the given symbol is not in the vertex list of G, the procedure will terminate reporting an error, otherwise the vertex of G with a label matching the given symbol will be used as initial. This parameter is optional, if no symbol is given, or if {} is passed, the first entry on the vertex list of G will be used. The return value can be one of three possibilities as follows: If draw is true, the procedure returns a graph H such that H is an MST for G. If draw is false, the procedure will return the edge list for H, this is so the value reported by Maple contains more useful information. If initial is a symbol not present in the vertex list of G, or if G is not a connected graph, the procedure will return the string "ERROR". Module definition and initialization > restart: with(graphtheory): PrimMST := module() option package; export Prim; Prim := proc (G::Graph, stepbystep::truefalse := false, draw::truefalse := true, initial := {}) local H :: list, V :: set, E :: set, e :: list, g::graph, a::list, discarded::set, initvert::set,total::int, uncheckedverts::int: #variable initialization H:={}: #List of edges of the MST E:=Edges(G,weights): #backup of G's edge list, used in destructive operations uncheckedverts:=nops(vertices(g))-1: #number of G's vertices not yet reached by the MST

if initial <> {} then #determines initial vertex if initial in Vertices(G) then V:={initial}: #user-inputted initial vertex else printf("error: initial vertex not in graph"); return "ERROR": #invalid initial vertex else V:={E[1][1][1]}: #default initial vertex if draw and stepbystep then printf("key: yellow = vertices, magenta = initial vertex, blue = original graph edges,\n\tgreen = MST edges, red = discarded edges.\n"); discarded:={}: #discarded edge set, used only when drawing the graph initvert:=v: #initial vertex backup, used only when drawing the graph total:=0: #total weight of the edges in the MST while nops(e)>0 do; #continue while there are unprocessed edges e:={}: #assume no edge is added to the MST for a in E do: #for each edge if a[1][1] in V then if a[1][2] in V then E:=E minus {a}: #if it would cause a loop in the MST, discard the edge if stepbystep then #report discarded edge if the option is enabled printf("discarded edge (%a,%a) as it would cause a loop\n", a[1][1], a[1][2]): if draw then #draw resulting graph if the option is enabled discarded:=discarded union {a}: g:=graph([op(v)], discarded): HighlightSubgraph(G, g, red, yellow): HighlightVertex(G,initVert,magenta): print(drawgraph(g));

else if e={} or a[2]<e[2] then #if no loop is formed, take the minimum weight edge e:=a: else if a[1][2] in V and (e={} or a[2]<e[2])then e:=a: end do: if e<>{} then #if an edge of the MST was found, add it to the MST V:=V union {e[1][1], e[1][2]}: H:=H union {e}: E:=E minus {e}: total:= total+e[2]: uncheckedverts:=uncheckedverts-1: if stepbystep then #report added edge if the option is enabled printf("added edge (%a,%a) with weight %a to the MST\n", e[1] [1], e[1][2], e[2]): if draw then #draw resulting graph if the option is enabled g:=graph([op(v)], H): HighlightSubgraph(G, g, green, yellow): HighlightVertex(G,initVert,magenta): print(drawgraph(g)); if uncheckedverts=0 then #algorithm ends when all vertices are in the MST if stepbystep then #report end of computation if the option is enabled printf("finished MST construction.\n"): break: else if(e<>{})then #if there are unprocessed edges, but none of

them belongs to the MST, report an error printf("error: unable to construct MST, graph may be disconnected"); return "ERROR": end do: if (draw) then #print MST if the option is enabled g:=graph([op(v)],h): if stepbystep then printf("graph for the obtained MST:\n", a[1][1], a[1][2]): print(drawgraph(g)); printf("total weight of the MST: %a\n",total): #report total MST weight return g: #return graph for the MST else printf("total weight of the MST: %a\n",total): #report total MST weight return H; #return list of edges for the MST end proc: end module: with (PrimMST); Usage examples Default Behavior: print resulting MST, without step-by-step reports. > vertices:=["a","b","c","d"]: edges:={[{"a", "b"}, 1],[{"a", "c"}, 3],[{"b", "c"}, 2],[ {"b", "d"}, 5],[{"c", "d"}, 9]}: g := Graph(vertices,edges): Prim(g);

total weight of the MST: 8 Graph 1: an undirected weighted graph with 4 vertices and 3 edge(s) Shows step-by-step reports, but doesn't print the MST > vertices:=[1,2,3,4,5,6]: edges:={[{1,2},6],[{1,3},2],[{1,4},5],[{2,3},6],[{2,4},4],[ {2,5},5],[{3,4},6],[{3,5},3],[{3,6},2],[{4,5},6],[{5,6},2]}: g := Graph(vertices,edges): Prim(g,true,false); added edge (1,3) with weight 2 to the MST added edge (3,6) with weight 2 to the MST added edge (5,6) with weight 2 to the MST discarded edge (3,5) as it would cause a loop added edge (1,4) with weight 5 to the MST discarded edge (3,4) as it would cause a loop discarded edge (4,5) as it would cause a loop added edge (2,4) with weight 4 to the MST

Finished MST construction. total weight of the MST: 15 Shows step-by-step process with graphs for each step, using initial vertex "e" > vertices:=["a","b","c","d","e"]: edges:={[{"a","b"},3],[{"a","c"},2],[{"a","d"},2],[{"b","c"}, 5],[{"b","d"},2],[{"b","e"},4],[{"c","e"},1],[{"d","e"},7]}: g := Graph(vertices,edges): Prim(g,true,"e"); key: yellow = vertices, magenta = initial vertex, blue = original graph edges, = MST edges, red = discarded edges. added edge ("c","e") with weight 1 to the MST

added edge ("a","c") with weight 2 to the MST added edge ("a","d") with weight 2 to the MST

discarded edge ("d","e") as it would cause a loop

added edge ("b","d") with weight 2 to the MST

Finished MST construction. graph for the obtained MST:

total weight of the MST: 7 Graph 2: an undirected weighted graph with 5 vertices and 4 edge(s) (4.2.1) References Cook, William J. et. al. Combinatorial Optimization. Wiley-Interscience, 1998. ISBN 0-471-55894-X Legal Notice: 2016. Maplesoft and Maple are trademarks of Waterloo Maple Inc. Neither Maplesoft nor the authors are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the authors for permission if you wish to use this application in for-profit activities.