You are on page 1of 5

International Journal of Computer Science Trends and Technology (IJCST) – Volume 11 Issue 4, Jul-Aug 2023

RESEARCH ARTICLE OPEN ACCESS

Impact of Language on Sorting Algorithms: An Empirical Study


Nishita Raghavendra [1], Manushree Shah [2]
[1]
Student, Choithram School, Manik Bagh, Indore, Madhya Pradesh
[2]
B.Sc. (Hons), NMIMS University Navi Mumbai, Maharashtra

ABSTRACT
This research paper presents a comprehensive comparative analysis of sorting and searching algorithm execution speed in
three prominent programming languages: Python and Java. The study aims to assess the impact of language choice on the
performance of these fundamental operations, which are crucial in numerous applications and algorithms. The research
involves conducting experiments with representative datasets and implementing well-known algorithms. Bubble Sort, Quick
Sort, and Merge Sort algorithms were utilized for sorting, while Binary Search and Linear Search algorithms were employed
for searching. Execution times were measured and compared across the three languages. The findings reveal noteworthy
variations in execution speed among the sorting and searching algorithms in the three programming languages. The research
further explores the contributing factors behind these differences, including language features, memory allocation, and
compiler optimization techniques. It addresses potential limitations and implications of the findings, emphasizing the
significance of considering language performance when choosing an appropriate programming language for sorting and
searching tasks. Overall, this study provides valuable insights into the performance characteristics of sorting and searching
algorithms in Python and Java, enabling researchers and practitioners to make informed decisions regarding language
selection for efficient execution of these fundamental operations in diverse software applications.
Keywords: searching, sorting, execution, compiler, programming.

I. INTRODUCTION
Searching and sorting are fundamental operations in on factors such as the size of the data set, the initial order
computer science and play a crucial role in various of the elements, and the desired time complexity.
applications and algorithms. Both searching and sorting Efficient searching and sorting algorithms are crucial for
are essential tasks performed on data sets to organize and improving the performance of numerous applications, such
retrieve information efficiently. Understanding these as databases, information retrieval systems, computational
operations and their performance characteristics is vital for biology, and network routing. The execution speed and
developing efficient algorithms and optimizing software efficiency of these algorithms depend on various factors,
systems. including the choice of programming language, the
Searching refers to the process of finding a specific algorithm's design and implementation, and the
element or value within a given data set. It involves characteristics of the data set.
systematically examining the data to locate the desired In this research paper, we aim to compare the execution
item. Searching algorithms, such as Binary Search and speed of searching and sorting algorithms across three
Linear Search, are widely used to efficiently locate prominent programming languages: Python, and Java. By
elements in both ordered and unordered data sets. The evaluating and analysing the performance of these
choice of a suitable searching algorithm depends on factors algorithms in different languages, we can gain insights into
such as the data set's size, order, and search requirements. the impact of language choice on the efficiency of these
On the other hand, sorting involves arranging a collection fundamental operations. This knowledge will enable
of elements in a specific order, such as numerical or researchers and practitioners to make informed decisions
alphabetical. Sorting algorithms rearrange the elements in when selecting the most appropriate language for their
a systematic manner, making it easier to search, analyze, specific searching and sorting requirements.
and process the data. Various sorting algorithms exist,
including Bubble Sort, Quick Sort, Merge Sort, and many II. LITERATURE REVIEW
others, each with its own advantages and performance
[1] In the paper, the author surveyed and categorized the
characteristics. The choice of a sorting algorithm depends
metadata required for a diverse set of Stanford Digital
Library services that they have built. Their metadata

ISSN: 2347-8578 www.ijcstjournal.org Page 44


International Journal of Computer Science Trends and Technology (IJCST) – Volume 11 Issue 4, Jul-Aug 2023

architecture fits into their established infrastructure and dynamically typed, so the variable type is checked during
promotes interoperability among existing and de-facto run time.
metadata standards. Several pieces of the architecture are
[6]. C, C++, java, perl, python, rexx and tcl were compared
implemented; others are under construction. The
in this study. Although Java still has a significant memory
architecture includes attribute model proxies, attribute
overhead when compared to C or C++ as of JDK 1.2.1
model translation services, metadata information facilities
(and on the Solaris platform), the run-time efficiency has
for search services, and local metadata repositories.
improved to an acceptable level. Even for applications
Together, these components provide, exchange, and
requiring a good degree of computation and data handling,
describe metadata for information objects and metadata for
the frequently used "scripting languages" Perl, Python,
information services.
Rexx, and Tcl can be viable alternatives to "conventional"
[2]. Author mentions that over the past several years, they languages like C or C++. At least for tiny programmes like
have analyzed the error-handling designs of a variety of the phone code problem, their relative run time and
critical applications and have discovered serious defects memory consumption overhead will frequently be
even in well-tested and mature systems. In the paper, they acceptable, and they may give considerable benefits in
describe specific recurring patterns of error handling terms of programmer productivity. A change in
defects which have been observed in critical systems. It programming language tends to account for fewer
seems clear that the design, implementation, and testing of variances between programs than interpersonal variability,
error handling are often not given adequate attention and which is the capacity and behaviour differences amongst
resources. programmers using the same language.
[3]. In this paper explains that recent progress in cognitive [7].Authors discusses about the impact on the memory of a
computing suggests that we might approach the point system due to programs with large datasets. A significant
when the algorithmic principles of brain-like computing performance bottleneck might occur from the subsequent
will be revealed and the study, design and realization of input/output communication, or I/O, between fast internal
thinking machines will start to be an issue in computer memory and slower external memory (such discs).
science. For this purpose, the author presents a brief
overview of related results from a machine-oriented
III. EXPERIMENTAL SETUP
complexity theory.
The experimental setup involved comparing the
[4]. The book of Z. Michalewicz has an important message
performance of two popular programming languages:
that is also reflected in the title. Namely, it advocates the
Python and Java. Both languages were chosen due to their
modem view that, regardless to representationdata
widespread usage and their capabilities in handling
structures), a problem solver can be seen as ‘evolutionary’
searching and sorting operations.
if it is based on the basic reproduction-selection cycle
genetic algorithms). The experimental set up was conducted on a suitable
device for both the languages.
[5].Author has compared Python and Java languages and
each of the two languages taken into account in this A. Searching Operations: The experiments included two
analysis has advantages and disadvantages specific to that commonly used searching algorithms: linear search and
field. The claim that one of them is superior to the other binary search. These algorithms were implemented
cannot be made with certainty. Although Java's structure is separately in both Python and Java.
a little more complicated than Python's, it offers a better Linear search is a basic searching algorithm that
grasp of memory management and is safer. Python is a
sequentially checks each element in a given list or array
small, easy language. Python programs are written in plain until the target value is found or the end of the list is
English, making them simple enough for a beginner to reached. It is a simple yet inefficient algorithm for large
grasp. Python's code is easier to read because indentation
datasets since it has a time complexity. However, it is
is required. But with Java, indentation has no effect and suitable for small or unsorted lists where the elements are
the entire program can be written in a single line to make it accessed sequentially. Linear search is easy to understand
appear shorter. Java is statically typed, so the precise
and implement, making it a common choice for simple
datatype for variables is known during compilation, search operations, hence we included it in our experiment.
leading to faster execution than Python, whereas Python is
Binary search is a more efficient searching algorithm that
is applicable to sorted lists or arrays. It follows a divide-

ISSN: 2347-8578 www.ijcstjournal.org Page 45


International Journal of Computer Science Trends and Technology (IJCST) – Volume 11 Issue 4, Jul-Aug 2023

and-conquer approach by repeatedly dividing the search scenario provides an understanding of the lower bounds of
space in half until the target value is found. Binary search an algorithm's performance and is used to determine the
has a time complexity, making it highly efficient for large best-case time complexity.
datasets. However, it requires the input to be sorted
The average case scenario refers to the expected
beforehand. Binary search is widely used in various
performance or behavior of an algorithm when it is
applications where efficient search operations are required,
executed on typical or randomly generated inputs. It takes
such as in searching databases or in certain data structures
into account the distribution of inputs and provides an
like balanced binary trees. It is more efficient than linear
estimate of how the algorithm is likely to perform on
search in a lot of aspects.
average. The average case scenario is often used to
B. Sorting Operations: The experiments involved evaluate the efficiency or time complexity of an algorithm.
implementing three popular sorting algorithms: quick sort,
The worst-case scenario represents the least favourable or
merge sort, and bubble sort. Each algorithm was
most challenging situation for an algorithm. It occurs when
implemented in both Python and Java.
the input data is in the worst possible order or when the
Quick sort is a popular sorting algorithm known for its algorithm encounters the most difficult-to-process
efficiency and simplicity. It follows a divide-and-conquer elements. The worst-case scenario helps establish the
approach, where it partitions the array based on a chosen upper bounds of an algorithm's performance and is used to
pivot element and recursively sorts the sub-arrays on either determine the worst-case time complexity. It provides
side of the pivot. Quick sort has an average time insight into how an algorithm might perform in the most
complexity, making it one of the fastest sorting algorithms. unfavourable conditions. Dataset for both the
It is widely used in various applications due to its excellent programming languages were the same, and generated in
average-case performance, but it can have a worst-case the code itself
time complexity in certain scenarios.
IV. RESULTS
Merge sort is a stable and efficient sorting algorithm that
also employs the divide-and-conquer strategy. It The purpose of this study was to compare the efficiency of
recursively divides the input array into smaller sub-arrays, searching and sorting operations between Python and Java,
sorts them individually, and then merges them back two widely-used programming languages. The goal was to
together to produce a sorted result. Merge sort has a determine which language is more suitable for performing
consistent time complexity in all cases, making it suitable these tasks and provide recommendations based on the
for large datasets. Although it requires additional space for findings.
merging the sub-arrays, merge sort is widely used due to
To assess the performance, we conducted a series of
its reliable performance and ease of implementation.
experiments and collected data on the execution time for
Bubble sort is a simple and straightforward sorting both operations. The data was analysed and summarised in
algorithm that repeatedly compares adjacent elements and Table 1 below:
swaps them if they are in the wrong order. It proceeds by
The results of the experiments indicate a notable difference
bubbling up the largest elements to the end of the array in
in execution speed between Python and Java across
each pass until the entire array is sorted. Bubble sort has a
various programs. In the best case scenarios, Python
time complexity, making it inefficient for large datasets. It
demonstrated significantly faster execution times
is primarily used for educational purposes or for sorting
compared to Java. For example, the execution time for
small, nearly sorted arrays due to its simplicity. However,
linear search in Python was 0.001186370849609375 ns,
due to its poor performance, it is rarely used in practical
whereas in Java it was considerably slower at 17954700
applications.
ns: even in the average case the difference was quite
We have also used three scenarios in searching operations visible as python require only 0.0019953250885009766 ns
to make it more efficient to be interpreted: best case, worst whereas Java required 2069500 ns . Similarly, the binary
case and average case. search in Python executed in 0.00099873542-78564453 ns,
while Java took substantially longer at 535300 ns in the
The best-case scenario represents the most favourable or
best case. As we look over the worst and average cases we
optimal situation for an algorithm. It occurs when the input
see a similar pattern with python at
data is in the best possible order or when the algorithm
0.0009953975677490234 ns with 0.000995635986328125
encounters the easiest-to-process elements. The best-case
ns and Java at 172500 ns with 575100 ns.

ISSN: 2347-8578 www.ijcstjournal.org Page 46


International Journal of Computer Science Trends and Technology (IJCST) – Volume 11 Issue 4, Jul-Aug 2023

In each scenario, Java's execution times were consistently -ribute Time), ns Time)
slower than Python. This is evident from the data, as the
worst-case execution times for linear and binary search in 1 Linear Best 0.0011863 17954700
Python were 0.0009970664978027344 and Search Case 708496093
0.000995397567 7490234 ns, respectively. In contrast, Scenari 75
Java's worst-case execution times were much higher at o
3574500 and 172500 ns for linear and binary search, 2 Linear Worst 0.0009970 3574500
respectively. These findings provide clear evidence Search case 664978027
supporting the analysis stated above. Scenari 344
o
In summary, the experimental results demonstrate that
Python consistently outperformed Java in terms of 3 Linear Averag 0.0015938 1755700
execution speed across the evaluated programs, including Search e Case 282012939
linear and binary search. These findings underscore the Scenari 453
superior performance of Python compared to Java for these o
specific operations.
4. Binary Best 0.0009987 535300
These findings suggest that Python is more efficient in Search Case 354278564
terms of operations when compared to Java. The observed Scenari 453
differences in execution time may be attributed to various o
factors, including differences in language design,
5. Binary Worst 0.0009953 172500
optimization techniques, and underlying algorithms. Search Case 975677490
Upon examining the sorting algorithms, a similar pattern Scenari 234
emerges, reaffirming the superiority of Python over Java in o
terms of speed. In the best-case scenarios, Python 6. Binary Averag 0.0009956 575100
exhibited significantly faster execution times in quick sort, Search e Case 359863281
merge sort, and bubble sort, with times of Scenari 25
0.0019969940185546875, 0.006139278411865234, and o
0.003048181533 8134766 ns, respectively. In contrast,
Java lagged behind considerably, with execution times of 7. Quick Best 0.0019969 13945400
Sort Case 940185546
13945400, 5069500, and 5427200 milliseconds for the
Scenari 875
respective sorting algorithms. o
Considering the worst-case scenario as well there was a
8. Quick Worst 0.0009980 22669500
similarity in our observations as Python was at
Sort Case 201721191
0.0009980201721191406, 0.0670239925 3845215 and Scenari 406
0.012440204 620361328 ns. Contrarily Java was once o
again slower with 22669500, 6963800 and 5461800 ns.
9. Merge Best 0.0061392 5069500
Further analysis of the data in the table reinforces this Sort Case 784118652
trend, as it becomes evident that Python consistently Scenari 34
outperforms Java across different scenarios. Whether o
considering the average case or best case, Python
consistently exhibits faster execution times than Java. 10. Merge Worst 0.0670239 6963800
Sort Case 925384521
In summary, the findings regarding sorting operations Scenari 5
align with the results obtained for searching. Python o
demonstrates superior performance over Java, showcasing
faster execution times across various; scenarios and sorting 11. Bubble Best 0.0030481 5427200
Sort Case 815338134
algorithms.
Scenari 766
Table -1: Analysis of execution speed
o
SL. ALGO- Parame PYTHON JAVA
NO RITHM ters/Att (Execution (Execution

ISSN: 2347-8578 www.ijcstjournal.org Page 47


International Journal of Computer Science Trends and Technology (IJCST) – Volume 11 Issue 4, Jul-Aug 2023

12. Bubble Worst 5461800 [5]. Khoirom, S., Sonia, M., Laikhuram, B.,
Sort case 0.0124402 Laishram, J., & Singh, T. D. (2020).
Scenari 046203613 Comparative analysis of Python and Java for
o 28 beginners. Int. Res. J. Eng. Tec hnol, 7(8), 4384-4407.
[3] Parkvall, S.; Astely, D., “The Evolution of
LTE towards IMT-Advanced”, Journal of
VI. CONCLUSION communications, Vol. 4, No. 3, 2009.
In conclusion, the comparative analysis of searching and
sorting operations between Python and Java demonstrates [6]. Prechelt, L. (2000). An empirical comparison
of c, c++, java, perl, python, rexx and tcl. IEEE
that Python outperforms Java in terms of execution speed.
Computer, 33(10), 23-29.
The experimental results consistently show that Python
exhibits faster execution times across various scenarios,
[7]. Vitter, J. S. (2001). External memory
including both searching and sorting tasks. Whether algorithms and data structures: Dealing with
examining best, worst, or average case scenarios, Python massive data. ACM Computing surveys (CsUR), 33(2),
consistently proves to be more efficient than Java. 209-271.

These findings suggest that Python is a more suitable Authors’ Profile


language for performing searching and sorting operations,
providing a compelling recommendation for its usage in
these contexts. The observed differences in execution Nishitha Raghavendra is a
times can be attributed to various factors, such as language student of grade 12 , in
design, optimization techniques, and underlying Choithram school, Manik
algorithms. bagh, Indore, and she is a
science stream students
Overall, this research highlights the superior performance doing specialization in
of Python over Java in terms of speed and efficiency for computer science along with
searching and sorting tasks. These findings can inform mathematics, physics and
developers and programmers in choosing the appropriate chemistry as the majors.
programming language for such operations, ultimately She has a special interest in exploring various machine
leading to improved performance and productivity. learning and artificial intelligence along with the
programming and astrophysics . At present she is
VIII. REFERENCES preparing for various engineering entrance exams
[1]. Baldonado, M., Chang, C.-C.K., Gravano, L., along with her project work in AI and ML.
Paepcke, A.: The Stanford Digital Library Metadata
Architecture. Int. J. Digit. Libr. 1 (1997) 108–121
Manushree Shah is a second-year student at NMIMS
[2]. Bruce, K.B., Cardelli, L., Pierce, B.C.: University, Navi Mumbai, pursuing her Bachelors in
Comparing Object Encodings. In: Abadi, M., Ito, T. Science (Honors) in Artificial Intelligence. She is a
(eds.): Theoretical Aspects of Computer Software. highly motivated and enthusiastic student with a
Lecture Notes in Computer Science, Vol. 1281. profound passion for technology and statistics.
Springer-Verlag, Berlin Heidelberg New York (1997) Fascinated by the endless possibilities offered by
415–438 technology, she is exploring deep into the realms of
[3]. Van Leeuwen, J. (ed.): Computer Science programming, data
analysis, and machine
Today. Recent Trends and Developments. Lecture
Notes in Computer Science, Vol. 1000. Springer- learning.
Verlag, Berlin Heidelberg New York (1995)
[4]. Michalewicz, Z.: Genetic Algorithms + Data
Structures = Evolution Programs. 3rd edn. Springer-
Verlag, Berlin Heidelberg New York (1996)

ISSN: 2347-8578 www.ijcstjournal.org Page 48

You might also like