0% found this document useful (0 votes)
76 views

Implementation of Selection Sort Algorithm in Various Programming Languages

Sorting algorithmdeals with the arrangement of alphanumeric data in static order.It plays an important roleinthe field of data science. Selection sort is one ofthe simplest and efficient algorithms which can be applied for the huge number of elements it works likeby giving list of unsorted information, the calculation which breaksintotwo partitions. One section has all the sorted information and another sectionhas all thestaying unsorted information. The ca

Uploaded by

Velumani s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Implementation of Selection Sort Algorithm in Various Programming Languages

Sorting algorithmdeals with the arrangement of alphanumeric data in static order.It plays an important roleinthe field of data science. Selection sort is one ofthe simplest and efficient algorithms which can be applied for the huge number of elements it works likeby giving list of unsorted information, the calculation which breaksintotwo partitions. One section has all the sorted information and another sectionhas all thestaying unsorted information. The ca

Uploaded by

Velumani s
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ISSN 2278-3091

Volume
Arisha Naz et al., International Journal of Advanced 10,
Trends in No.3, May
Computer - June
Science 2021
and Engineering, 10(3), May - June 2021, 2249 – 2255
International Journal of Advanced Trends in Computer Science and Engineering
Available Online at http://www.warse.org/IJATCSE/static/pdf/file/ijatcse1061032021.pdf
https://doi.org/10.30534/ijatcse/2021/1071032021

Implementation of Selection Sort Algorithm in Various


Programming Languages
Arisha Naz1, Haque Nawaz2, Abdullah Maitlo 3, Syed Muhammad Hassan4
1
BSCS Student, Department of Computer Science, Sindh Madressatul Islam University, Karachi, Sindh, Pakistan,
arisha.naz1234@gmail.com
2
Department of Computer Science, Sindh Madressatul Islam University, Karachi, Sindh, Pakistan,
hnlashari@smiu.edu.pk
3
Department of Computer Science, Shah Abdul Latif University, Khairpur Mirs, Sindh, Pakistan,
abdullah.maitlo@salu.edu.pk
4
Department of Computer Science, Sindh Madressatul Islam University, Karachi, Sindh, Pakistan,
m.hassan@smiu.edu.pk

At the point when given selection of unsorted information,


ABSTRACT the calculation was partition the rundown into two sections:
one section that has all the sorted information and another
Sorting algorithm deals with the arrangement of part that has all the staying unsorted information. At the point
alphanumeric data in static order. It plays an important role in when the calculation initial beginnings, there is no
the field of data science. Selection sort is one of the simplest information in the initial segment neither in sorted order at
and efficient algorithms which can be applied for the huge this point and all the unsorted information is in the
number of elements it works like by giving list of unsorted subsequent part. The calculation at that point begins to locate
information, the calculation which breaks into two partitions. the smallest element in the unsorted information and trade it
One section has all the sorted information and another section with the furthest is to be the left component of the run down.
has all the staying unsorted information. The calculation The part with the sorted information is then the furthest is the
rehashes itself, by finding the smallest component inside the left component and the part with the unsorted information is
rundown of unsorted information and swapping it with the to be the staying unsorted components. The calculation
furthest left component, in the end setting everything straight rehashes itself, by finding the smallest component inside the
information. This research presents the implementation of rundown of unsorted information and trading it with the
selection sort using C/C++, Python, and Rust and measured furthest left component, in the end setting everything straight
the time complexity. After experiment, we have collected the information [2].
results in terms of running time, and analyzed the outcomes. 1.1 Selection Sort Algorithm Working
It was observed that python language has very small amount  Find the lowest number.
of line of code, and it also consumes less storage and fast  Move it with the initial value.
running time then other two languages.  Find the second lowest number.
 Move it with the second value.
Key words: Selection Sort, Time Complexity, Algorithm  Find the third-lowest number
Implementation, C/C++, Python, Rust, Comparison.  Move it with the third value.
 Repeat finding the next lowest value, and moving it into the
correct place until the array is sorted
1. INTRODUCTION
Selection sort is an algorithm used for sorting easily it is very 1.2 Selection Sort Complexity
simple, it divide the list into two parts and do sort the problem Selection sort isn't hard to investigate contrasted with other
in a way that right part contain unsorted numbers and left sorting techniques since none of the replacement relies upon
part contain sorted number similarly it revolves over files in the information in the cluster. Choosing the base requires
checking n components and afterward exchanges it in to the
the cluster; for each file, selection sort calls minimum record
primary position. Finding the following most reduced
and line of work. In the event that the length of the exhibit is components requires examining the remaining n-1 is the
n, there are n files in the cluster. Hence each outcome of the components, etc. Hence, the absolute number of the
body of the program runs code of two lines. It may feel that correlations is regarding number of correlations. Every one
two n, number lines of program are debugged by selection of these steps requires one swap for n-1 is components [3].
sort. However, a few lines of code are executed on recollected
record in minimum [1].

2249
Arisha Naz et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2249 – 2255

2. LITERATURE REVIEW For instance, that the C is conventional choice, C++ for those
Initially a part of this moves surround the advantages and with that desire to start object with-direction. The Java is
disadvantages of the language platforms which can be utilized moreover selected because it's cutting edge and adaptable
to display program. It would complain on to the simplest language, yet in addition because it's generally the language
language platform as long as, because at the level of once own individuals see as a replacement standard. These three it was
choice. Starting an aspect of the moves to the focal points and likely significant because they it were our most appreciated
drawbacks of the language stages which was be used to show non-Python choices. C was utilized before in our initial
program. Clearly, it would criticize on to the most courses when C++ is likewise normal and it is-built up
straightforward language stage as long as it can imagine, language inside our courses. Java is at that of point being used
because that is to all at the degree of once own choice of a on some advanced programming courses and along these
self-want. In any case, in the event that it investigates the vast lines expected choice. On the other side Python is a
majority of the people groups – the novice software engineers deciphered language, however the before referenced dialects
– it was endeavor to discover a language that offers best help are compiler-based, so direct comparison between them was
to the larger part of them and meets their requirements. So, in off the mark. In this Rex and Perl [6]. It would be known
what capacity would it be a good idea for it to choose the inside the summary to deftly additional reference focuses
learning platform for the initial programming course? inside the case of deciphered dialects against compiler-based
Common answer main point is that restart and can be used to dialects generally. Within the writing review it even that
selected the common central and present language usable to Matlab found there was a discussion on to the sum of earlier
access, even inside new developer’s case, some other problem work to compare though it wasn’t so much an childish
can be shown. It can be apply to the language stage that must language stage in customary sense [7]. Different algorithms
be simple together all enough one that could become known studied and different platforms explored [9-15], and come up
with the needs of the language, similar to factors, access and with idea to implement the selection sort algorithm in various
rule over the techniques of stream or Input/output activities programming languages.
not even much of an initial that comes with the formal syntax
and documentation [4]. 3. RESEARCH METHODOLOGY
Moreover, on the other side, simplicity shouldn't be a In this comparative analysis, selection sort algorithm is
constraint once it advances to the more complicated aspects. evaluated in C/C++, Python, Rust languages to distinguish
Another significant factor ought to be accessibility. It would the complexity of algorithm using software’s such as: Dev
be best to use it with the point where circumstances useable to
C++, turbo C, Python and online Rust programming site to
higher education, something be said about those people that
need to or necessities to-learn at home. It’s basic to be set up to implement code of selection sort as all the language have
give some common, publicly accessible list of options that are different number of line of codes and compilation process,
practical, and in best case potentially free from charges. find the best language for this algorithm and highlighted the
Furthermore, in the event that it considers this from the best platform from the different implemented code and
perspective of the instructional exercise in organizations, it outcomes:
most likely wouldn't damage to have menu that don't
accompany some sort of license expense. In the event that the 3.1 Selection Sort – Algorithm Complexity
menu is accessible for a few working frameworks, the stage In Selection Sort Time Complexity for all the cases, worse
wouldn't cause issues, which may even be being a strong case, best case or average case remain same as O(n2) [8].
component. End point that includes to the choices is that the
takeover credit. Improvements like, utilization circumstances
Table 1: Selection Sort Case Complexity
that stages to customized language which shows the essential
to the scholars, yet these conditions urge to became old when Selection Comparison Swap
individuals improve towards difficult levels. Credibility factor
in addition reflects to the initial language stages, potential Best Case O(n2) O(n)
which can have for being complete aspects, at any rate 2
Average Case O(n ) O(n)
tragically lack the assistance from the marketing perspective 2
Worst Case O(n ) O(n)
[5]. So all around the preliminary social issue of language
even more precisely, the main criteria for inclusion was that
4. IMPLEMENTATION AND RESULT ANALYSIS
the language expected to fulfill the above fundamentals and
Selection sort move the numbers within the array. Each
was a neither it more likely and commonly utilized language
stage like Java, that has recently been proposed as an essential number change and swap position, it finds the index of the
language stage inside the few prior examinations like Python. smallest number within the subset begin at that place.
Which language stages did it choose other than it? The main Number changes its position with the smallest number.
common gathering of comparison, C, C++ and Java might be Implement selection sort with different languages with
a for the most part great gathering of 6 examples of each of multiple data size and analyze the results with respect to
them because they have little special dedications to start with.
complexity.
2250
Arisha Naz et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2249 – 2255

4.1 C/C++Algorithm: other for move that's messing numbers in the outer for
1. Discover the minimal array to its size sorting.
2. Get index of minimal data
So, let given a string of N to putting an array, the choice a
3. Setting in accurate position type set of discipline has the subsequent time and complexity
4. Create an array with great variety of element values. The time complexity of O (n2) is in particular due
5. Type the sorted array to the usage for circular move. The best kind approach by
no means takes more than O(n) swaps and is useful
4.1.1 Flowchart of selection sort in C/C++ whilst the recollection write operation proves to be
expensive[4].

Start
4.1.3 Running time
For calculating running time we run code for three times by
Read array increasing the number of element in array and got different
length amount of time but not more than a minute it takes time in
seconds to execute the output but time depend on the no of
element if the element extend then running time also exceed.
Print list
Table 2: Data Set Size and Time of Execution
S. no No of Elements Time in seconds
1 5 9.916
I <n-1 2 10 23.3
3 15 25.1

J<=n-1

Arr(j)<arr(min_ind
ex)

Swap list I
and j

Figure 1: Time of execution in C/C++


Print sorted list

4.2 Python Algorithm:


1. It shows what number of things it re arranged
Stop
2. To locate the base estimation of the unsorted portion
4.1.2 Time Complexity: 3. It initially accept that the main component is the most
reduced
Selection sort calls for repeated over n over changes mess
4. min_index = I
with every start to finish itself. The element move through all
5. It at that point use j to round through the rest of the
of the numbers within place of the array till end of the string
components
and it discover the smallest detail index the work of some

2251
Arisha Naz et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2249 – 2255

6. Update the min_index if the component at j is smaller 4.2.2 Time Complexity:


than it. The sort complexity is utilized to communicate the quantity of
7. In the list of finding the most reduced element of the execution times it takes to sort the rundown. The usage has
unsorted array, exchange with the principal unsorted two times.
The external recursion which picks the qualities individually
element.
from the rundown is executed n times where n is the all-out
8. END number of qualities in the rundown. The inward circle, which
looks at the incentive from the external recursion with the
4.2.1 Flowchart of selection sort in python remainder of the qualities, is likewise executed n times where
n is the absolute number of components in the rundown.
Along these lines, the extent of executions is (n * n), which
can likewise be communicated as O(n2).
Start The selection sort has three classes of complicated nature to
be specific;
Worst case – this is the place the rundown gave is in dropping
request. The calculation plays out the most extreme number of
Read array length executions which is communicated as [Big-O] O (n2)
Best case – this happens when the given list has arranged. The
calculation plays out the base number of executions which is
communicated as [Big-Omega] Ω (n2)
Set i=0 Average case – this happens when the rundown is in arbitrary
request. The normal complicated nature is communicated as
[Big-theta] ⊝(n2) [9]
No
I <n-1 4.2.3 Running time
For calculating running time run code for three times by
increasing the number of element in array and got different
amount of time but not more than a minute it takes seconds to
Set min index= i
execute the output but time depends on the no of element if the
element extend then running time also exceed but it’s very
faster to execute than c language.

Set j= i+1 Table 3: Data Set Size and Time of Execution


S. no No of Elements Time in seconds
1 5 1.39
2 10 2.5
Arr(j)<arr(min_index)
3 15 3

Time of excution in pyhton

Set min index= j 4


time in sec

3
2
Time in
Sorted array 1
seconds
0
5 10 15
no of element
Stop
Figure 2: Time of execution in python

2252
Arisha Naz et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2249 – 2255

4.3 Rust Algorithm: 4.3.2 Time Complexity:


1. The set of rules perspectives the elements. Selection sort calls for recursion over n over changes mess
2. A looked after element, and an unsorted element. with every different to finish itself. One for movement
3. At the beginning, it viewed after element is empty, move through all of the numbers within place of the array
and the whole listing was the unsorted element. till end of the string and it
4. One at a time the smallest detail within array discover the smallest detail index of next element the
the unsorted element is moved to the last looked exchange the messing number in the array [9].
element. The selection sort has three classes of complicated nature to
be specific;
4.3.1 Flow chart of selection sort in Rust Worst case – this is the place the rundown gave is in dropping
request. The calculation plays out the most extreme number of
executions which is communicated as [Big-O] O (n2)
Start Best case – this happens when the given list is arranged. The
calculation plays out the base number of executions which is
communicated as [Big-Omega] Ω (n2)
Average case – this happens when the rundown is in arbitrary
For i=1 to request. The normal multifaceted nature is communicated as
n-2 [Big-theta] ⊝(n2) [10].

4.3.3 Running time


For calculating running time run code for three times by
i min = 1 increasing the number of element in array and got different
amount of time but not more than a minute it takes seconds to
execute the output but time depend on the number of element
if the element extend then running time also exceed.

For i=1 to Table 2: Data Set Size and Time of Execution


n-2
S. No No of elements Time in seconds
1 5 10
2 10 16.56
3 15 20.33
If a(j)<a()

i min = j

Time of execution in Rust


30
no of elment

20
10 Time in
seco nds
0
Exchange a(i)and a(i min)
5 10 15
time(sec)

Figure 3: Time of execution in Rust

Stop

2253
Arisha Naz et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2249 – 2255

5. RESULTS AND DISCUSSION REFERENCES


As result, it gains the outcome that they have little bit of [1] J. B. Hayfron-acquah and P. D, “Improved Selection
difference but not difficult selection is easiest if list given Sort Algorithm,” International Journal of Computer
Applications, vol. 110, no. 5, pp. 29–33, 2015.
number of array is to be mention to be sorted and it take very
[2] R. N. Vilchez, “Bidirectional Enhanced Selection Sort
small amount of time to be execute and according to this Algorithm Technique,” International Journal of
implementation on different language python consume less Applied and Physical Sciences, vol. 5, no. 1, pp. 28–35,
time than any other two languages and it can be shown in the 2019.
below through the table and graph. [3] T. M. Fagbola and S. C. Thakur, “Investigating the
Effect of Implementation Languages and Large
Table 3: Comparison of data size Problem Sizes on the Tractability and Efficiency of
S. no No of Time in second Sorting Algorithms,”International Journal of
Element C/C++ Python Rust Engineering Research and Technology, vol. 12, no. 2, p.
1 5 9.9 1.39 10 196-203, 2019.
2 10 23.3 2.5 16.56 [4] H. Fangohr, “A Comparison of C, MATLAB, and
3 15 25.1 3 20.33 Python as Teaching Languages in Engineering,” in
Computational Science - ICCS 2004, Berlin,
Heidelberg, 2004, pp. 1210–1217.
doi: 10.1007/978-3-540-25944-2_157.
Compairison between
[5] D. E. Knuth, The art of computer programming,
C/C++,Python,&Rust volume 3. Addison Wesley Longman Publishing Co.,
time in sec

60 Inc.350 Bridge Pkwy suite 208 Redwood City, CAUnited


States, 1998. Accessed: Jun. 15, 2021. [Online].
40
Rust Available: https://dl.acm.org/doi/book/10.5555/280635
20
[6] M. Stein, and A. Geyer-Schulz), “A Comparison of
0 Python Five Programming Languages in a Graph Clustering
5 10 15 C/C++ Scenario,” Journal of Universal Computer Science, vol.
19, no. 3, pp. 428–456, 2013.
no of element [7] D. K. Kavitha, “Comparative Study of Various
Enhanced Selection Sort Algorithm,” International
Figure 4: Comparison of time of execution between C/C++, Python Journal of Engineering Research, vol. 3, no. 30, pp. 1–3,
and Rust 2015.
[8] F. G. Furat, “A Comparative Study of Selection Sort
In terms of memory storage python consume less storage as and Insertion Sort Algorithms,” International
compare to other two languages as shown in the table below Research Journal of Engineering and Technology
the reason why it is take less time to execute and less memory (IRJET), vol. 03, no. 12, pp. 326–330, 2016.
hold its already define array in source file but other two define [9] D. Rajagopal and K. Thilakavalli, “Different Sorting
Algorithm’s Comparison based Upon the Time
array size that hold more memory to execute the program.
Complexity,” IJUNESST, vol. 9, no. 8, pp. 287–296,
Aug. 2016, doi: 10.14257/ijunesst.2016.9.8.24.
[10] M. Abdulla, “Selection Sort with Improved
6. CONCLUSION Asymptotic Time Bounds,” The International Journal
In this study, we have explored the performance of selection Of Engineering And Science (IJES), vol. 5, no. 5, pp.
sort algorithm in terms of complexity by using different 125–130, 2016.
platforms, such as C/C++, Python, and Rust language. We [11] I. Ali, H. Nawaz, I. Khan, A. Maitlo, M. Ameen, and M.
have collected the results in terms of running time, and Malook, “Performance Comparison between Merge
analyzed the outcomes. It was observed that python language and Quick Sort Algorithms in Data Structure,”
International Journal of Advanced Computer Science
has very small amount of line of code, and it also consumes
and Applications, vol. 9, no. 11, 2018.
less storage and fast running time then other two languages. It doi: 10.14569/IJACSA.2018.091127.
has concluded that selection sort has less complexity using [12] S. M. Aqib, H. Nawaz, and S. M. Butt, “Analysis of
python platform as compared to c/c++ and rust platform. Merge Sort and Bubble Sort in Python, PHP,
JavaScript, and C language,” International Journal of
Advanced Trends in Computer Science and
Engineering, vol. 10, no. 2, pp. 680–686, Apr. 2021.
doi: 10.30534/ijatcse/2021/311022021.

2254
Arisha Naz et al., International Journal of Advanced Trends in Computer Science and Engineering, 10(3), May - June 2021, 2249 – 2255

[13] M. A. Hingoro and H. Nawaz, “A Comparative


Analysis of Search Engine Ranking Algorithms,”
International Journal of Advanced Trends in Computer
Science and Engineering, vol. 10, no. 2, pp. 1247–1252,
Apr. 2021, doi: 10.30534/ijatcse/2021/1081022021.
[14] F. A. Agha and H. Nawaz, “Comparison of Bubble and
Insertion Sort in Rust and Python Language,”
International Journal of Advanced Trends in Computer
Science and Engineerin, vol. 10, no. 2, pp. 1020–1025,
Apr. 2021, doi: 10.30534/ijatcse/2021/761022021.
[15] H. Ali and H. Nawaz, “Performance Analysis of Heap
Sort and Insertion Sort Algorithm,” International
Journal of Emerging Technologies in Engineering
Research (IJETER), vol. 9, no. 5, pp. 580–586, May
2021, doi10.30534/ijeter/2021/08952021.

2255

You might also like