Performance Analysis of Heap Sort and Insertion Sort Algorithm
Performance Analysis of Heap Sort and Insertion Sort Algorithm
Volume
Humaira Ali et al., International Journal of Emerging 9. No.
Trends 5, May 2021
in Engineering Research, 9(5), May 2021, 580 – 586
International Journal of Emerging Trends in Engineering Research
Available Online at http://www.warse.org/IJETER/static/pdf/file/ijeter08952021.pdf
https://doi.org/10.30534/ijeter/2021/08952021
ABSTRACT Sorting algorithm works as if the input is given like (7, 6, 4,
9, 2, 0, and 1) so it gives us output in sequential order (0, 1,
In the era of new technology, we have huge amount of data to 2, 4, 6, 7, and 9). For the analysis of best case numbers is
deal with arranging the huge amount of data has remained a organized in sequential order and in average case number is
big challenge. This research paper includes two types of organized in unsystematic order, and in worst case number is
sorting algorithm, Heap Sort and Insertion Sort and also their organized in reducing order.
performance analysis on the basis of running time along with
their complexity. This paper includes the algorithms and their
So it is clear that sorting is important for managing data.
implementation in Java programming language. For the
Due to their major role in managing data appropriately,
results of this research study, the comparison of these two
many algorithms have been discovered for example, bubble
sorting algorithms with different type of the data at running
sort, quick sort, merge sort, selection sort etc...
time such as Large, Average, and Small. In Large, data
pass100 integers in the array. For Average data pass 50 These all algorithms work for different domains. Some of
integers in the array and for Small data pass10 integers in the these algorithms are useful for sorting small data, some for
array. It checks that, which sorting technique is efficient large and some for average data. However, depends on their
according to the input data. Then identifies the efficiency of performance and time complexity in programming
these algorithms according to this data three cases used that is languages like java[3]. An Insertion Sort performs with
Best, Average and Worst Case. The result of this analysis is order of n^2 and Heap Sort perform the order of nlogn [4].
showing with the help of graphs to show that how much time
1.1 Insertion Sort Algorithm Working
both algorithms take while given the desired output.
As shown in figure 1 insertion sort divides the input data
Key words: Array, Complexity, Heap Sort, Insertion Sort, into sorted and unsorted data and then compares the
Performance, Sorting Algorithm. unsorted part with the sorted data, if the data in the unsorted
part is less than sort that data is in its accurate position[5]
1. INTRODUCTION [6].
The efficiency of the algorithm depends upon the time and Figure 1: Insertion Sort Working Process
space taken by the given data [2].
580
Humaira Ali et al., International Journal of Emerging Trends in Engineering Research, 9(5), May 2021, 580 – 586
581
Humaira Ali et al., International Journal of Emerging Trends in Engineering Research, 9(5), May 2021, 580 – 586
3. METHODOLOGY
582
Humaira Ali et al., International Journal of Emerging Trends in Engineering Research, 9(5), May 2021, 580 – 586
In this phase, the complexity can be check in three ways: Large Data
0.062
1. Best Case
0.061
2. Average Case
0.06
3. Worst Case
0.059
So according to these cases in best case the data in array is Time in Seconds
arranged in sequential order, in average case the data in array 0.058
Time in Seconds
is arranged in random order and in worst case the data in 0.057
array is arranged in decreasing order.
0.056
Analysis for Best Case: Insertion Sort Heap Sort
0.0565
Time in Seconds Small Data
0.056 Time in Seconds 0.0582
0.058
0.055 0.0578
5 Insertion Sort Heap Sort 0.0576
0.0574 Time in Seconds
0.0572 Time in Seconds
Figure 5: Represent Small Data In Best Case. 0.057
0.0568
0.0566 Insertion Sort Heap Sort
583
Humaira Ali et al., International Journal of Emerging Trends in Engineering Research, 9(5), May 2021, 580 – 586
0.8
Large Data
Average Data
0.7
0.065 0.6
0.5
0.064 0.4 Time in Seconds
0.3 Time in Seconds
0.063
0.2
Time in Seconds
0.1
0.062 Time in Seconds
0
0.0615
Insertion Sort Heap Sort
Insertion Sort Heap Sort
Figure 13: Represent Large Data In Worst Case.
Figure 10: Represent Large Data In Average Case.
4. 3 Phase III (Comparison):
In average case the insertion sort works best for all types of
data as compared to heap sort. In this phase the comparison of heap and insertion sort is
performed by using the best, average and worst case on small,
Analysis for Worst Case: large and average data set. Figure 14 presents the comparison
of insertion and heap sort on small data set. Figure 15 presents
In the analysis of worst case the data that is tested is in the comparison of insertion and heap sort on average data set, and
decreasing form. The analysis can be performing on large, Figure 16 presents the comparison of insertion and heap sort on
small and average set of data. Figure 11 presents small data in large data set.
worst case, Figure 12 presents average data in worst case, and
Figure 13 presents large data in worst case.
0.066
0.064
Small Data 0.062
0.08 0.06 Best Case
0.058 Average Case
0.06
0.056
Worst Case
0.04 0.054
Time in Seconds
0.052
0.02 Time in Seconds
0.05
0
Insertion Sort Heap Sort
Insertion Heap
Figure 11: Represent Small Data In Worst Case. Figure 14: Represent The Comprison of Insertion and Heap Sort
on Small Data Set.
0.0585
Average Data 0.058
0.063
0.0575
0.062
0.057
0.061 Best Case
0.0565
0.06 0.056 Average Case
Time in Seconds 0.0555
Worst Case
0.059 Time in Seconds
0.055
0.058
0.057
Insertion Heap
Insertion Sort Heap Sort
Figure 12: Represent Average Data In Worst Case. Figure 15: Represent The Comprison of Insertion and Heap Sort
on Average Data Set.
584
Humaira Ali et al., International Journal of Emerging Trends in Engineering Research, 9(5), May 2021, 580 – 586
585
Humaira Ali et al., International Journal of Emerging Trends in Engineering Research, 9(5), May 2021, 580 – 586
586