MODIFIED KRUSKAL ALGORITHM USING BOX SORT FOR MINIMUM SPANNING TREE

Similar documents
Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Lecture 34 Fall 2018 Wednesday November 28

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Minimum-Cost Spanning Tree. Example

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

What is a minimal spanning tree (MST) and how to find one

Design and Analysis of Algorithms

Minimum Spanning Trees

Info 2950, Lecture 16

Lecture Summary CSC 263H. August 5, 2016

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Spanning Trees. Lecture 20 CS2110 Spring 2015

Algorithm Design and Analysis

Minimum Spanning Trees My T. UF

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Chapter 23. Minimum Spanning Trees

The minimum spanning tree problem

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

23.2 Minimum Spanning Trees

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

COP 4531 Complexity & Analysis of Data Structures & Algorithms

A New Quick Algorithm for Finding the Minimal Spanning Tree

CSE 21: Mathematics for Algorithms and Systems Analysis

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CS61B, Fall 2002 Discussion #15 Amir Kamil UC Berkeley 12/5/02

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP)

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

7.3 Spanning trees Spanning trees [ ] 61

tree follows. Game Trees

Fuzzy Region Merging Using Fuzzy Similarity Measurement on Image Segmentation

CS521 \ Notes for the Final Exam

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Recitation 13. Minimum Spanning Trees Announcements. SegmentLab has been released, and is due Friday, November 17. It s worth 135 points.

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Greedy algorithms. Given a problem, how do we design an algorithm that solves the problem? There are several strategies:

CS 161: Design and Analysis of Algorithms

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

PowerPoint Presentation to Accompany GO! All In One. Chapter 13

Minimum Spanning Tree (undirected graph)

Algorithms for Minimum Spanning Trees

INSERTION SORT APPROACH FOR THE CAR SEQUENCING PROBLEM

Elementary Graph Algorithms: Summary. Algorithms. CmSc250 Intro to Algorithms

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

CSC 1700 Analysis of Algorithms: Minimum Spanning Tree

Greedy Algorithms. Previous Examples: Huffman coding, Minimum Spanning Tree Algorithms

Spanning Trees. Lecture 22 CS2110 Spring 2017

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Announcements Problem Set 5 is out (today)!

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

Minimum Spanning Tree

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

LECTURE 26 PRIM S ALGORITHM

Constrained Minimum Spanning Tree Algorithms

Weighted Graphs and Greedy Algorithms

We ve done. Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding

Minimum Spanning Trees

Minimum spanning trees

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

CSE 5311 Notes 4a: Priority Queues

CSE 2320 Notes 6: Greedy Algorithms

Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

1. Sorting (assuming sorting into ascending order) a) BUBBLE SORT

Introduction: (Edge-)Weighted Graph

Minimum Spanning Trees

Unit 3 Fill Series, Functions, Sorting

Unit 3 Functions Review, Fill Series, Sorting, Merge & Center

Week 11: Minimum Spanning trees

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

SPANNING TREES. Lecture 21 CS2110 Spring 2016

CS302 - Data Structures using C++

Minimum Spanning Trees

22 Elementary Graph Algorithms. There are two standard ways to represent a

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

So on the survey, someone mentioned they wanted to work on heaps, and someone else mentioned they wanted to work on balanced binary search trees.

Greedy Algorithms. COMP 215 Lecture 6

Example of why greedy step is correct

6.1 Minimum Spanning Trees

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

MST & Shortest Path -Prim s -Djikstra s

Minimum Spanning Trees. CSE 373 Data Structures

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Math 15 - Spring Homework 5.2 Solutions

Algorithm Design (8) Graph Algorithms 1/2

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Minimum Spanning Trees Ch 23 Traversing graphs

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

18 Spanning Tree Algorithms

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

22 Elementary Graph Algorithms. There are two standard ways to represent a

Context: Weighted, connected, undirected graph, G = (V, E), with w : E R.

CSE 521: Design and Analysis of Algorithms I

Transcription:

3-04 Kruskal Algorithm Modification Using Box Sort For Finding Minimum Spanning Tree MODIFIED KRUSKAL ALGORITHM USING BOX SORT FOR MINIMUM SPANNING TREE Bilqis Amaliah, Rarasmaya Indraswari, Ria Yunita Sari Informatics Department, FTIf, Institut Teknologi Sepuluh Nopember (ITS) Jl. Raya ITS, Surabaya 60111 bilqis@if.its.ac.id ABSTRACT Modified kruskal algorithm using box sort is proposed to improve the running time for finding the minimum distance of spanning tree. The proposed method can decrease the running time of former kruskal algorithm because it uses several boxes for sorting edge. To evaluate the performance of proposed method, the graph with 10 vertices and more than 20 vertices are used. The result shows that for graph with less than 20 vertices, the running time almost same between former and modified kruskal algorithm. For many vertices, the running time of modified kruskal algorithm is 16% faster than former kruskal algorithm. Keywords : Kruskal algorithm, Minimal Spanning Tree, Sorting. 1 INTRODUCTION Minimum spanning tree is a graph with no cycle and have minimum total cost edge. There are many cases for minimum spanning tree, for example : Wang using minimum spanning tree to calculate the similarity at foreign exchange market [1], Zhang using minimum spanning tree for modeling America economic at 2010 [2], Spelta using minimum spanning tree to analyze crossborder financial [3], Ferreira using GRASP and cut generation algorithm to solve the general minimum spanning tree [4]. Prim algorithm and Kruskal algorithm are common algorithm to solve the minimum spanning tree problem [1]. In the Kruskal algorithm, edges in the graph are sorted first based on the weight from the smallest to the largest using one box. For many vertices more than 20, the running time of kruskal algorithm will be slow. Modified kruskal algorithm using box sort is proposed to improve the running time for finding the minimum distance of spanning tree. Kruskal algorithm is selected because it s a common algorithm and have opportunity to develop. This is a greedy algorithm, so there are many ways to decrease the running time. The proposed method can decrease the running time of former kruskal algorithm because it uses several boxes for sorting edge. Former kruskal algorithm use one box for sorting the edge, so it takes time to sorting the graph with more than 20 vertices. Modified kruskal algorithm sort the edge in several boxes, so it can be decreased the running time. After that, kruskal algorithm is used to find the minimum spanning tree. To evaluate the performance of proposed method, the graph with 10 vertices and 15 edges, 20 vertices and 70 edges, 20 vertices and 100 edges, 50 vertices and 200 edges, 100 vertices and 500 edges, 100 vertices and 700 edges are used. The running time of former kruskal algorithm will be compared with modified kruskal algorithm. Relation the number of box and running time will be analyzed. The kruskal algorithm is introduced in 2. Box sort is proposed in 3. A modified kruskal algorithm is proposed in 4. The result is shown in 5. The conclusion is shown in 6. 2 KRUSKAL ALGORITHM There are two methods for the minimum spanning tree: Kruskal algorithm and Prim algorithm [5]. Kruskal algorithm is an algorithm to find the minimum spanning tree based on the MST (Minimum Spanning Tree) general algorithm. In Kruskal algorithm, first, edges in the graph G are sorted based on the weight from the smallest to the largest. Edge from graph G is added to graph T if it does not form a cycle in T. Each edge is inserted into graph T. Graph T is a tree. The difference between Prim and Kruskal algorithm is in Prim algorithm edges that inserted into T should be associated with a node in T, meanwhile in Kruskal algorithm the selected edge 87

The 7 th International The Proceedings Conference of The 7th ICTS, on Bali, Information May 15th-16th, & 2013 Communication (ISSN: 9772338185001) Technology and Systems does not need to be associated with a node in T with terms the insertion does not form a cycle. The steps of Kruskal algorithm is as follow [5] : 1. Sort each edge in the graph, starting from the smallest edge into the largest one. 2. Select an edge which has the minimum weight and does not formed a cycle in the tree. Add the edge to the tree. 3. Repeat step 2 until the minimum spanning tree is formed, until the number of edges in the minimum spanning tree is n-1 (n is the number of vertices in the graph). 3 BOX SORT Sorting is the process of sorting value either ascending or descending. Sorted values can be numeric or character (alphanumeric) type. The sorted data can be in memory (internal sort) and may also be in external storage (external sort). Box sort algorithm is an algorithm that puts edges into several box. Then edges in each box sorted individually. Box sort algorithm is as follow : Determine the edges that will be sorted Determine the number of box and the range of each box Insert edges into the appropriate box (box with range corresponding to the edge weight) Inside the box, sort the edges using bubble sort Put the edges that have been sorted to the initial array. Figure 1. Edges are inserted into the box Figure 2. Sorting each box. 4 MODIFIED KRUSKAL ALGORITHM Modified Kruskal algorithm is the former Kruskal algorithm with modify at sorting edge. Sorting is done separately using box sort. Former kruskal algorithm use one box for sorting the edge. Modified kruskal algorithm use several box for sorting the edge The steps of modified Kruskal with box sort to determine the minimal spanning tree : 1. Determine the minimum cost (min) and the maximum cost (max) from all the costs of edges in the graph. 2. Determine the range (max min), determin the number of box (b), determine the interval of each box (intv = range / b; and the result is rounded up). 3. Insert all edges into the appropriate box (for example : edge with cost = 28 is inserted into box with interval 26.1 33). Example : min = 12, max = 46, b = 5; so the range = 46-12 = 34, and interval = range / b = 34:5 = 7; so the interval of b[1] is 12.0-19.0, interval of b[2] is 19.1-26.0, interval of b[3] is 26.1-33.0, interval of b[4] is 33.1-40.0, and interval of b[5] is 40.1-47.0. Cost 32 will be inserted into b[3] and cost 16 will be inserted into b[1], and so on. If the costs of edges in the graph are sequence (the values don t vary much) then there will not be a lot of empty boxs. A box is empty if there is no edge in the graph whose value is in the interval of the box. 4. After all the box are formed (all costs of edges in the graph are inserted in the appropriate boxs), then sort the existing edges in the box. Place the edge with the lowest cost at top of the heap. 88

The 7 th International 3-04 Conference Kruskal Algorithm on Information Modification Using & Communication Box Sort For Finding Minimum Technology Spanning and TreeSystems 5. At the first box (box with the lowest interval), remove the edge that was on top of the heap and checks whether it forms cycle in the spanning tree. If not, then add that edge to the minimal spanning tree. 6. Take the edge that is (now) on the top (because of edge above it has been taken) and add them to the spanning tree (don t forget to check the cycle) until the heap is empty or the minimum spanning tree has been formed. 7. If the minimum spanning tree has not been established yet, move to the next box and do step 5-6 until the last box, or finally the minimum spanning tree has been formed. In the program, to check there is cycle or not is characterized by root. When an edge is selected (for example: the edge connecting vertices 8 and 4) the root of n1 is 8 and the root of n2 is 4. If vertex 8 previously is connected to another vertex (for example: vertex 9) then root of n2 become 9. If vertex 4 previously is connected to another vertex (for example: vertex 9) then root of n1 become 9, and so on. The last root value will be shown in program. If roots of n1 and n2 are same, it means there is cycle and that edge will not be inserted into the spanning tree. If roots of n1 and n2 are different, it means there is no cycle and that edge can be inserted in the spanning tree.. Table 1. The test results of running time, compare between original and modified Kruskal Vertex Edge Kruskal Modified Box Sort 20 70 60 42 5 45 10 47 15 20 100 85 57 5 60 10 63 15 50 200 132 97 5 103 10 110 15 100 500 158 140 5 145 10 150 15 100 700 200 175 5 180 10 185 15 Rata-rata 127 106,6 It can be seen from table 1 that modify kruskal is faster than former kruskal. Running time for modify kruskal is 106,6 in average and former kruskal is 127 in average. So, modify kruskal is 16% faster than former kruskal. From table 1, the running time is lower when number of box is 5. More box is more time. Example problem for minimum spanning tree. 5 RESULT Program can explain step by step undertaken by both former and modified Kruskal algorithm. In addition to find the minimum spanning tree using the algorithms, our program is also capable of displaying the result of running time that is required by the algorithms. The steps to run the program : 1. Run the program. User can choose to enter input manually, from file.txt, or random input. 2. For example : user choose to enter input from file.txt. 3. User can choose to finish the problem with original or modified Kruskal algorithm. 4. Each step will be evident. 5. The end result is minimal spanning tree. 6. Generate running time to run the program. Figure 3. Example problem for MST with 10 vertex and 15 edge. The test results of running time compare between original and modified Kruskal are presented at table 1. 89

The 7 th International The Proceedings Conference of The 7th ICTS, on Bali, Information May 15th-16th, & 2013 Communication (ISSN: 9772338185001) Technology and Systems Input Menu : Using Kruskal algorithm: Figure 4. Input menu Input File (contoh.txt): Figure 5.. Input from file In input file, the number of vertex = 10, the number of edge = 15, for the next rows is edge that connecting one vertex to another, follow by cost. If user chooses manual input, then user has to input the value manually. If user chooses random, then user input number of vertex and number of edge, cost edge will randomly. Output Menu : Figure 7. Output using kruskal Display program if user choose modified kruskal using box sort. First, user has to input number of box, then program will display cost edge minimal and cost edge maximal, following with interval for each box. Figure 6. Output Menu 90

The 7 th International 3-04 Conference Kruskal Algorithm on Information Modification Using & Communication Box Sort For Finding Minimum Technology Spanning and TreeSystems of vertex is 10, less than 20 vertexes, than effectiveness modify is not clear enough. For number of vertex less than 20, modify kruskal running time is longer than normal kruskal because there is box sort. But, box sort is useful if the number of vertex is more than 20. 6 CONCLUSION 1. The running time for the graph with 10 vertex and 15 edge, is not really different between modified kruskal and former kruskal. 2. To evaluate the performance of proposed method, the graph with 20 vertices and 70 edges, 20 vertices and 100 edges, 50 vertices and 200 edges, 100 vertices and 500 edges, 100 vertices and 700 edges are used. The result is modified kruskal 16% faster than former. 3. For the graph with 20 vertices and 70 edges, 20 vertices and 100 edges, 50 vertices and 200 edges, 100 vertices and 500 edges, 100 vertices and 700 edges, the lower running time is achieve when the number of box sort is 5. Next research Comparing modified krukal with other MST algorithm. Trying a few sorting method for box sort. REFERENCE Figure 8. Output using Mofidy kruskal From this example, total cost for modified kruskal is 224 dan 77 ms for running time. Running time for former kruskal is 76 ms, formar kruskall is faster 1 ms than modified kruskal, because number [1] Wang. G, Xie. C, Similarity measure and topology evolution of foreign exchange markets using dynamic time warping method: Evidence from minimal spanning tree, Physica A, 391, 2012, 4136 4146 [2] Zhang. Y, Lee. G, Will the US economy recover in 2010? A minimal spanning tree study, Physica A, 390, 2011, 2020 2050 [3] Spelta. A, Araujo. T, The topology of crossborder exposures: Beyond the minimal spanning tree approach, Physica A, 391, 2012, 5572 5583 [4] Ferreira. C, Ochi. L, A GRASP-based approach to the generalized minimum spanning tree problem, Expert Systems with Applications, 39, 2012, 3526 3536 [5] Taha. H, Operation Research an Introduction, New Jersey, Prentice Hall, eight edition, 2007 91

The 7 th International The Proceedings Conference of The 7th ICTS, on Bali, Information May 15th-16th, & 2013 Communication (ISSN: 9772338185001) Technology and Systems [This page is intentionally left blank] 92