II. NORMAL BUBBLE SORT (WORST CASE)

Similar documents
Performance Visualization of Bubble Sort in Worst Case Using R Programming in Personal Computer

CS Lecture 5. Vidroha debroy. Material adapted courtesy of Prof. Xiangnan Kong and Prof. Carolina Ruiz at Worcester Polytechnic Institute

Determining Occurrence in FMEA Using Hazard Function

Rearrangement of Recognized Strokes in Online Handwritten Gurmukhi. words recognition.

CFD Analysis ofwind Turbine Airfoil at Various Angles of Attack

A Point-Based Algorithm to Generate Final Table States of Football Tournaments

ZIN Technologies PHi Engineering Support. PHi-RPT CFD Analysis of Large Bubble Mixing. June 26, 2006

A Novel Decode-Aware Compression Technique for Improved Compression and Decompression

WINNING AND SCORE PREDICTOR (WASP) TOOL

GOLOMB Compression Technique For FPGA Configuration

CFD Analysis and Experimental Study on Impeller of Centrifugal Pump Alpeshkumar R Patel 1 Neeraj Dubey 2

Critical Gust Pressures on Tall Building Frames-Review of Codal Provisions

Youth Sports Leagues Scheduling

DESIGN AND ANALYSIS OF ALGORITHMS (DAA 2017)

A Study on Weekend Travel Patterns by Individual Characteristics in the Seoul Metropolitan Area

Online Companion to Using Simulation to Help Manage the Pace of Play in Golf

Heap Sort. Lecture 35. Robb T. Koether. Hampden-Sydney College. Mon, Apr 25, 2016

Algorithm for Line Follower Robots to Follow Critical Paths with Minimum Number of Sensors

67. Sectional normalization and recognization on the PV-Diagram of reciprocating compressor

Analysis and realization of synchronized swimming in URWPGSim2D

A Fair Target Score Calculation Method for Reduced-Over One day and T20 International Cricket Matches

Volume 2, Issue 5, May- 2015, Impact Factor: Structural Analysis of Formula One Racing Car

International Journal of Technical Research and Applications e-issn: , Volume 4, Issue 3 (May-June, 2016), PP.

Reduction of Bitstream Transfer Time in FPGA

Influence of rounding corners on unsteady flow and heat transfer around a square cylinder

ANALYSIS OF AERODYNAMIC CHARACTERISTICS OF A SUPERCRITICAL AIRFOIL FOR LOW SPEED AIRCRAFT

Study on Mixing Property of Circulation/Shear Coupling Mechanism-Double Impeller Configuration

THEORETICAL EVALUATION OF FLOW THROUGH CENTRIFUGAL COMPRESSOR STAGE

Wind turbine Varying blade length with wind speed

A COMPARATIVE STUDY OF MIX FLOW PUMP IMPELLER CFD ANALYSIS AND EXPERIMENTAL DATA OF SUBMERSIBLE PUMP

Unmanned Aerial Vehicle Failure Modes Algorithm Modeling

A Computational Assessment of Gas Jets in a Bubbly Co-Flow 1

A Model for Tuna-Fishery Policy Analysis: Combining System Dynamics and Game Theory Approach

The Incremental Evolution of Gaits for Hexapod Robots

Investigation of Stresses in Ring Stiffened Circular Cylinder

Numerical Simulation And Aerodynamic Performance Comparison Between Seagull Aerofoil and NACA 4412 Aerofoil under Low-Reynolds 1

Measurement of the Best Z-Factor Correlation Using Gas Well Inflow Performance Data in Niger-Delta

Fitness for Service Assessment of Ageing Pressure Vessel Experiencing External Corrosion: A Case Study

EFFICIENCY OF TRIPLE LEFT-TURN LANES AT SIGNALIZED INTERSECTIONS

DESIGN AND ANALYSIS OF DIFFERENT TYPES OF FIN CONFIGURATIONS USING ANSYS

Safety Analysis Methodology in Marine Salvage System Design

Computer Integrated Manufacturing (PLTW) TEKS/LINKS Student Objectives One Credit

Measuring Heterogeneous Traffic Density

Experimental and Theoretical Investigation for the Improvement of the Aerodynamic Characteristic of NACA 0012 airfoil

LABORATORY EXPERIMENTS ON WAVE OVERTOPPING OVER SMOOTH AND STEPPED GENTLE SLOPE SEAWALLS

SUPPLEMENT MATERIALS

International Journal of Advance Research in Engineering, Science & Technology

A IMPROVED VOGEL S APPROXIMATIO METHOD FOR THE TRA SPORTATIO PROBLEM. Serdar Korukoğlu 1 and Serkan Ballı 2.

Three New Methods to Find Initial Basic Feasible. Solution of Transportation Problems

Compensator Design for Speed Control of DC Motor by Root Locus Approach using MATLAB

Dynamics of the bubble near a triangular prism array

Vibration Analysis and Test of Backup Roll in Temper Mill

SIMULATION OF ENTRAPMENTS IN LCM PROCESSES

An approach for optimising railway traffic flow on high speed lines with differing signalling systems

SSRG International Journal of Mechanical Engineering (SSRG-IJME) volume 4 Issue 12 December 2017

ENHANCED PARKWAY STUDY: PHASE 2 CONTINUOUS FLOW INTERSECTIONS. Final Report

Water Treatment: Fundamentals and Practical Implications of Bubble Formation

Kinematic and Finite Element Analysis of a Master Slave Manipulator Gripper

The Study of Bubbly Gas-Water Flow Using

Aerodynamic Measures for the Vortex-induced Vibration of π-shape Composite Girder in Cable-stayed Bridge

Computational Analysis of Cavity Effect over Aircraft Wing

International Journal of Modern Trends in Engineering and Research e-issn No.: , Date: 2-4 July, 2015

A study on the relation between safety analysis process and system engineering process of train control system

PJD Connection. . TenarisHydril Running Manual.. Recommended guidelines for the field inspection of TenarisHydril connections, FSOG

Planning and Design of Proposed ByPass Road connecting Kalawad Road to Gondal Road, Rajkot - Using Autodesk Civil 3D Software.

Aerodynamic Design, Fabrication and Testing of Wind Turbine Rotor Blades

CFD Simulation and Experimental Validation of a Diaphragm Pressure Wave Generator

Designing of Low Power and Efficient 4-Bit Ripple Carry Adder Using GDI Multiplexer

Modal Analysis of Propulsion Shafting of a 48,000 tons Bulk Carrier

23 RD INTERNATIONAL SYMPOSIUM ON BALLISTICS TARRAGONA, SPAIN APRIL 2007

Performance Analysis of Centrifugal Compressor under Multiple Working Conditions Based on Time-weighted Average

New Viscosity Correlation for Different Iraqi Oil Fields

Available online at Procedia Engineering 200 (2010) (2009)

Design of Low Power and High Speed 4-Bit Ripple Carry Adder Using GDI Multiplexer

Correlation analysis between UK onshore and offshore wind speeds

1 GENERAL PROCEDURES THAT APPLY TO ANY RACE

ANALYSIS OF RUBBER FORMING PROCESS OF FIRE BARRIER FROM TITANIUM CP2 ALLOY FOR AW 139 HELICOPTER

Design and Analysis of Reactor Dish Vessel

A computational study on structural barrier to vertical spread of window spill plume along building exterior façade under external wind

The Orienteering Problem

Determination of the Design Load for Structural Safety Assessment against Gas Explosion in Offshore Topside

RELIABILITY ASSESSMENT, STATIC AND DYNAMIC RESPONSE OF TRANSMISSION LINE TOWER: A COMPARATIVE STUDY

A Conceptual Approach for Using the UCF Driving Simulator as a Test Bed for High Risk Locations

Conversation of at Grade Signalized Intersection in to Grade Separated Intersection

RELATIONSHIP OF SELECTED KINEMATIC VARIABLES WITH THE PERFORMANCE OF DOUBLE HANDEDBACKHAND IN TENNIS. Rajesh Kumar, M.P.Ed,

u = Open Access Reliability Analysis and Optimization of the Ship Ballast Water System Tang Ming 1, Zhu Fa-xin 2,* and Li Yu-le 2 " ) x # m," > 0

Fast Floating Point Compression on the Cell BE Processor

Investigation on 3-D Wing of commercial Aeroplane with Aerofoil NACA 2415 Using CFD Fluent

Environmental Science: An Indian Journal

Simulation and mathematical modeling for racket position and attitude of table tennis

Quantifying the Bullwhip Effect of Multi-echelon System with Stochastic Dependent Lead Time

SIDDHARTH INSTITUTE OF ENGINEERING & TECHNOLOGY :: PUTTUR (AUTONOMOUS) Siddharth Nagar, Narayanavanam Road QUESTION BANK (DESCRIPTIVE)

CHARACTERISTICS OF LEAK DETECTION BASED ON DIFERENTIAL PRESSURE MEASUREMENT

AIRFLOW GENERATION IN A TUNNEL USING A SACCARDO VENTILATION SYSTEM AGAINST THE BUOYANCY EFFECT PRODUCED BY A FIRE

ISSN: Page 410

Simulation Study of Dedicated Bus Lanes on Jingtong Expressway in Beijing

In memory of Dr. Kevin P. Granata, my graduate advisor, who was killed protecting others on the morning of April 16, 2007.

Physical Fitness For Futsal Referee Of Football Association In Thailand

Hunting for the Sweet Spot by a Seesaw Model

Test Method of Trap Performance for Induced Siphonage

Transcription:

A New Approach to Improve Worst Case Efficiency of Bubble Sort Vipul Sharma * Department of Computer Science & Engineering National Institute of Technology (Srinagar, J&K) Abstract Sorting is one of the most common operations in computer science, being a fundamental operation, sorting is defined as an activity which involves rearrangement of elements in either ascending order or descending order. There are a number of sorting algorithms that have been proposed for one reason or another, but this paper focuses on bubble sort algorithm. Here in this paper I have proposed a new technique that will enhance the performance of normal bubble sort, when used in worst case scenario. Further the experimental results that have been produced by using this new technique has been compared with normal bubble sort and insertion sort and it has been found, that the performance of the proposed algorithm is much better than the previous ones. Keywords bubble sort, complexity, worst case, algorithm, performance, comparisons. I. INTRODUCTION Sorting is defined as the process of arranging a given set of elements in either ascending order or descending order. Let us consider a set A of n elements, A 1, A 2, A 3..A n in memory. Sorting of A, refers to rearranging the elements of the set in increasing order, that is, A 1 < = A 2 < = A 3 < =.. < = A n.[1] There are a variety of algorithms available for performing this kind of rearrangement. Although a large number of algorithms have been developed but no single sorting algorithm is best suited for all the applications. Sorting algorithms find their usage in a variety of applications in real life and many other computer applications. This reason has widened the scope of research in this field. Sorting algorithms can broadly be classified into internal sorting and external sorting. In case of internal sorting the elements to be rearranged are present in the main memory. Where as in case of external sorting the elements to be sorted are large in number hence they reside in external sources other than the main memory.[1] Here in this paper I have proposed a new approach to improve the worst case performance of bubble sort by reducing the number of comparisons. The rest of the paper is organized as follows: Section II describes the bubble sort algorithm followed by section III where performance of simple bubble sort has been analyzed. Section IV would be presenting the new approach to enhance the worst case performance of bubble sort. Section V & VI describes the performance analysis of new approach and comparison of proposed algorithm with normal bubble sort and insertion sort. Finally section VII would include the conclusion followed by references. A. Working of Bubble sort. II. NORMAL BUBBLE SORT (WORST CASE) Consider a list of numbers A[1], A[2], A[3],..A[N] in memory. Bubble sort algorithm would work as follows: Step 1: - Compare A[1] with A[2] and rearrange them in desired fashion such that A[1] < A[2]. After this compare A[2] with A[3] and arrange them so that A[2] < A[3]. Continue in this fashion until you compare A[N-1] with A[N] and rearrange them such that A[N-1] < A[N]. [1] After step 1 A[N] would contain the largest element. It should be noted that step 1 involves (n-1) comparisons. Step 2: - Repeat step 1with one comparison less. This means that here in this step, we will stop when A[N-2] is compared with A[N-1]. [1] After step 2 A[N-1] would hold the second largest element in the list. It should be noted that step 2 involves (n-2) comparisons. Step 3: - Repeat step 1 with two less comparisons. This means that here in this step, we will stop after rearranging A[N-3] and A[N-2]. [1] Follow the above given sequence until you compare A[1] with A[2]. After (n-1) steps bubble sort would produce the sorted list. B. Pseudocode for Bubble sort. Bubble Sort (A[],n) Here A is the list of unsorted elements and n is the length of the array. After completion of the algorithm array A will be arranged in ascending order (sorted). 1. Repeat step 2 for i = 0 to n-2 2. Repeat step 3 for j= 0 to n-i-2 3. If (A[j]>A[j+1]) 2014-15, IRJCS- All Rights Reserved Page -54

Interchange A[j] and A[j+1] End if [2] C. Worst Case Example of Bubble sort. Consider the following list of elements in reverse order (The worst case scenario): - 78, 68, 58, 48, 38, 28, 18 Here number of elements to be sorted is 7. If we apply normal bubble sort the algorithm will sort the elements after 6 th pass i.e. (n-1) steps. Pass 1: - 78 68 58 48 38 28 18 68 78 58 48 38 28 18 68 58 78 48 38 28 18 68 58 48 78 38 28 18 68 58 48 38 78 28 18 68 58 48 38 28 78 18 68 58 48 38 28 18 78 End of Pass 1, Bold elements indicates the elements to be compared. (Number of comparisons 6 i.e. (n-1)) Pass 2: - 68 58 48 38 28 18 78 58 68 48 38 28 18 78 58 48 68 38 28 18 78 58 48 38 68 28 18 78 58 48 38 28 68 18 78 58 48 38 28 18 68 78 End of Pass 2, (Number of comparisons 5 i.e. (n-2)) Pass 3: 58 48 38 28 18 68 78 48 58 38 28 18 68 78 48 38 58 28 18 68 78 48 38 28 58 18 68 78 48 38 28 18 58 68 78 End of Pass 3, (Number of comparisons 4 i.e. (n-3)) Pass 4: 48 38 28 18 58 68 78 38 48 28 18 58 68 78 38 28 48 18 58 68 78 38 28 18 48 58 68 78 End of Pass 4, (Number of comparisons 3 i.e. (n-4)) Pass 5: 38 28 18 48 58 68 78 28 38 18 48 58 68 78 28 18 38 48 58 68 78 End of Pass 5, (Number of comparisons 2 i.e. (n-5)) Pass 6: 28 18 38 48 58 68 78 End of Pass 6, (Number of comparisons 1 i.e. (n-6)). After Pass 6 th i.e. (n-1 th ) Bubble sort will produce the sorted list. 18, 28, 38, 48, 58, 68, 78. 2014-15, IRJCS- All Rights Reserved Page -55

III. PERFORMANCE ANALYSIS OF NORMAL BUBBLE SORT (WORST CASE) The performance of any sorting algorithm can be measured on two parameters, first being the number of comparisons and second being number of swaps. Keeping the worst case into consideration the performance results are as: - A. Number of comparisons: Total number of comparisons for worst case scenario (n-1) + (n-2) + (n-3) +. (n-1) + (n-2) +..+ 3 + 2 +1. n*(n-1)/2 O(n 2 ). In above example n= 7. Therefore, number of comparisons: - 7*(7-1)/2 = 21(comparisons). B. Number of swaps: Total number of comparisons for worst case scenario (n-1) + (n-2) + (n-3) +. (n-1) + (n-2) +..+ 3 + 2 +1. n*(n-1)/2 O(n 2 ). In above example n= 7. Therefore, number of comparisons: - 7*(7-1)/2 = 21(swaps). A. Working of proposed algorithm IV. PROPOSED ALGORITHM The working of proposed algorithm to enhance the performance of bubble sort (in worst case) is as given below: Step no. 1: - Begin with first element of the reversed array and compare it with the last element, if A[front] > A[last], swap them. After this consider the second element and the second last element, again if A[front+1] > A[last-1], swap them. Continue in this fashion until you have either a single element remaining in the list or when two consecutive middle elements have been compared. Step no. 2: - Apply normal bubble sort algorithm on the list produced as a result from step no. 1. B. Pseudo code for proposed algorithm. improved_bubble_sort(a[0..n-1]) front=0, last=n-1; while(front < last) { if(a[front] > A[last]) { interchange(a[front], A[last]); } front++; last--; } Call normal_bubble_sort(a[0 n-1]). //Call normal bubble sort. C. Worst case example of improved bubble sort Consider the following list of elements in reverse order (The worst case scenario): - 78, 68, 58, 48, 38, 28, 18 Step no. 1: a) 78 68 58 48 38 28 18 Compare 78 with 18, since 78 > 18 so swap them. b) 18 68 58 48 38 28 78 2014-15, IRJCS- All Rights Reserved Page -56

Compare 68 with 28, since 68 > 28 so swap them. c) 18 28 58 48 38 68 78 Compare 58 with 38, since 58 > 38 so swap them. d) Since, only one element remains in the middle. So, go to step no. 2 (No of comparisons & swaps = n/2) Step no. 2: - Apply normal bubble sort on the above generated list. Pass 1: Pass 2: Pass3: Pass4: Pass5: Pass6: Bold elements indicates the elements to be compared. (No. of comparisons = n-1 & no. of swaps = 0). V. PERFORMANCE ANALYSIS OF PROPOSED ALGORITHM. Performance of proposed algorithm is also analyzed keeping into consideration the worst case scenario. A. Number of comparisons As indicated by the above example. It has been found that the number of comparisons in step no. 1 of the algorithm is n/2 and that in step no. 2 is (n-1). Combining both step 1 & step 2 we get: n/2 + (n-1) (2(n-1) + n)/2 (2n-1+n)/2 3n-1/2 O(n). B. Number of swaps The number of swaps in step no. 1 is n/2 & that in step no. 2 is 0. Combining both we get: n/2 + 0 n/2 O(n). VI. COMPARISON OF PROPOSED ALGORITHM WITH EXISTING ALGORITHMS. The proposed algorithm has been compared with normal bubble sort and insertion sort on different size of input elements in reverse order. Results obtained are as shown in the table given below: - 2014-15, IRJCS- All Rights Reserved Page -57

TABLE 1 Comparison of proposed algorithm with existing ones. Input size Bubble sort Insertion sort Proposed Algorithm (Improved bubble sort) No. of comparisons No. of comparisons No. of comparisons 15 105 105 22 55 1485 1485 82 220 24090 24090 329 350 61075 61075 524 512 130816 130816 767 405 81810 81810 607 850 360825 360825 1274 600 179700 179700 899 750 280875 280875 1124 890 395605 395605 1334 910 413595 413595 1364 1200 719400 719400 1799 VII. CONCLUSION So, it is clear from the results that the algorithm that I have proposed here, gives better results than the normal bubble sort and insertion sort when applied on large input size taken in reverse order. REFERENCES [1] Data Structures by Seymour Lipschutz, Schaum s outlines, The MacGraw Hill Companies. [2] Khairullah Md., Enhancing worst sorting algorithms, International Journal of Advanced Science & Technology, Vol. 56, July, 2013. [3] Levitin A., Introduction to the Design & Analysis of Algorithms, 2 nd Ed. Pearson Educational, 2007. [4] Oyelami Olufemi Moses, Improving the performance of bubble sort using a modified diminishing increment sorting Covenant University, P. M. B. 1023, Ota, Ogun State, Nigeria. [5] Ming Zhou, Hongfa Wang, An Efficient Selection Sorting Algorithm for Two Dimensional Arrays, Zhejiang Water Conservancy and Hydropower College Hangzhon, China. [6] Sartaj S. (2000). Data Structures, Algorithms & Applications in Java, McGraw-Hill. [7] E. Kapur, P. Kumar and S. Gupta, Proposal of a two way sorting algorithm and performance comparison with existing algorithms, International Journal of Computer Science, Engineering & Applications (IJCSEA), Vol. 2, No. 3, (2012), pp. 61-78. 2014-15, IRJCS- All Rights Reserved Page -58