Академический Документы
Профессиональный Документы
Культура Документы
insertion sort
Abstract
In this paper, we proposed a new efficient sorting algorithm based on insertion sort concept. The proposed algorithm called Bidirec-
arXiv:1608.02615v2 [cs.DS] 12 Aug 2016
tional Conditional Insertion Sort (BCIS). It is in-place sorting algorithm and it has remarkably efficient average case time complexity
when compared with classical insertion sort (IS). By comparing our new proposed algorithm with the Quicksort algorithm, BCIS
indicated faster average case time for relatively small size arrays up to 1500 elements. Furthermore, BCIS was observed to be faster
than Quicksort within high rate of duplicated elements even for large size array.
Keywords: insertion sort, sorting, Quicksort, bidirectional insertion sort
1. Introduction selection sort, bubble sort etc. The second group is O(n log n),
which is faster than the first group, includes Quicksort ,merge
Algorithms have an important role in developing process of sort and heap sort [12]. The insertion sort algorithm can be
computer science and mathematics. Sorting is a fundamen- considered as one of the best algorithms in its family (O(n2 )
tal process in computer science which is commonly used for group ) due to its performance, stable algorithm ,in-place, and
canonicalizing data. In addition to the main job of sorting al- simplicity [34]. Moreover, it is the fastest algorithm for small
gorithms, many algorithms use different techniques to sort lists size array up to 28-30 elements compared to the Quicksort algo-
as a prerequisite step to reduce their execution time [20]. The rithm. That is why it has been used in conjugate with Quicksort
idea behind using sorting algorithms by other algorithm is com- [30, 31, 36, 4] .
monly known as reduction process. A reduction is a method
for transforming one problem to another easier than the first Several improvements on major sorting algorithms have been
problem [32]. Consequently, the need for developing efficient presented in the literature [22, 9, 29]. Chern and Hwang [7]
sorting algorithms that invest the remarkable development in give an analysis of the transitional behaviors of the average cost
computer architecture has increased. from insertion sort to quicksort with median-of-three. Fouz et
Sorting is generally considered to be the procedure of reposi- al [13] provide a smoothed analysis of Hoares algorithm who
tioning a known set of objects in ascending or descending order has found the quicksort. Recently, we meet some investiga-
according to specified key values belong to these objects. Sort- tions of the dual-pivot quicksort which is the modification of
ing is guaranteed to finish in finite sequence of steps[8]. the classical quicksort algorithm. In the partitioning step of the
Among a large number of sorting algorithms, the choice of dual-pivot quicksort two pivots are used to split the sequence
which is the best for an application depends on several factors into three segments recursively. This can be done in different
like size, data type and the distribution of the elements in a data ways. Most efficient algorithm for the selection of the dual-
set. Additionally, there are several dynamic influences on the pivot is developed due to Yaroslavskiy question [37]. Nebel,
performance of the sorting algorithm which it can be briefed as Wild and Martinez [24] explain the success of Yaroslavskiys
the number of comparisons (for comparison sorting), number of new dual-pivot Quicksort algorithm in practice. Wild and Nebel
swaps (for in-place sorting),memory usage and recursion [1]. [35] analyze this algorithm and show that on average it uses
Generally, the performance of algorithms measured by the 1.9n ln n + O(n) comparisons to sort an input of size n, beat-
standard Big O(n) notation which is used to describe the com- ing standard quicksort, which uses 2n ln n + O(n) comparisons.
plexity of an algorithm. Commonly, sorting algorithms has Aumuller and Dietzfelbinger [2] propose a model that includes
been classified into two groups according to their time complex- all dual-pivot algorithms, provide a unified analysis, and iden-
ity. The first group is O(n2 ) which contains the insertion sort, tify new dual-pivot algorithms for the minimization of the aver-
age number of key comparisons among all possible algorithms.
Corresponding
This minimum is 1.8n ln n + O(n). Fredman [14] presents a
author
Email addresses: adnshr@gmail.com (Adnan Saher Mohammed),
new and very simple argument for bounding the expected run-
emrah@eng.ankara.edu.tr (Sahin Emrah Amrahov), ning time of Quicksort algorithm. Hadjicostas and Lakshmanan
fvcelebi@ybu.edu.tr (Fatih V. Celebi) [17] analyze the recursive merge sort algorithm and quantify
Preprint submitted to Future Generation Computer Systems August 16, 2016
the deviation of the output from the correct sorted order if the 50% is achieved within the range of elements of 28-more than
outcomes of one or more comparisons are in error. Bindjeme 3000000. The other pros of BCIS that it can sort equal elements
and Fill [6] obtain an exact formula for the L2-distance of the array or remain equal part of an array in O(n) .
(normalized) number of comparisons of Quicksort under the This paper is organized as follows: section-2 presents the
uniform model to its limit. Neininger [25] proves a central proposed algorithm and pseudo code, section-3 executes the
limit theorem for the error and obtain the asymptotics of the proposed algorithm on a simple example array, section-4 illus-
L3 distance. Fuchs [15] uses the moment transfer approach to trates the detailed complexity analysis of the algorithm, section-
re-prove Neiningers result and obtains the asymptotics of the 5 discusses the obtained empirical results and compares them
L p distance for all 1 p < . with other well-known algorithms, section-6 provides conclu-
Grabowski and Strzalka [16] investigate the dynamic behav- sions. Finally, you will find the important references.
ior of simple insertion sort algorithm and the impact of long-
term dependencies in data structure on sort efficiency. Bier-
nacki and Jacques [5] propose a generative model for rank data 2. The proposed algorithm BCIS
based on insertion sort algorithm. The work that presented
in [3] is called library sort or gapped insertion sort which is The classical insertion sort explained in [23, 19, 26] has one
trading-off between the extra space used and the insertion time, sorted part in the array located either on left or right side. For
so it is not in-place sorting algorithm. The enhanced insertion each iteration, IS inserts only one item from unsorted part into
sort algorithm that presented in [33] is use approach similar to proper place among elements in the sorted part. This process
binary insertion sort in [27], whereas both algorithms reduced repeated until all the elements sorted.
the number of comparisons and kept the number of assign- Our proposed algorithm minimizes the shifting operations
ments (shifting operations) equal to that in standard insertion caused by insertion processes using new technique. This new
sort O(n2 ). Bidirectional insertion sort approaches presented in technique supposes that there are two sorted parts located at the
[8, 11]. They try to make the list semi sorted in Pre-processing left and the right side of the array whereas the unsorted part
step by swapping the elements at analogous positions (position located between these two sorted parts. If the algorithm sorts
1 with n, position 2 with (n-1) and so on). Then they apply the ascendingly, the small elements should be inserted into the left
standard insertion sort on the whole list. The main goal of this part and the large elements should be inserted into the right
work is only to improve worst case performance of IS [11] . On part. Logically, when the algorithm sorts in descending order,
other hand, authors in[34] presented a bidirectional insertion insertion operations will be in reverse direction. This is the idea
sort, firstly exchange elements using the same way in [8, 11] behind the word bidirectional in the name of the algorithm.
, then starts from the middle of the array and inserts elements Unlike classical insertion sort, insertion items into two sorted
from the left and the right side to the sorted portion of the main parts helped BCIS to be cost effective in terms of memory
array. This method improves the performance of the algorithm read/write operations. That benefit happened because the length
to be efficient for small arrays typically of size lying from 10-50 of the sorted part in IS is distributed to the two sorted parts in
elements [34] . Finally, the main idea of the work that presented BCIS. The other advantage of BCIS algorithm over classical
in [23], is based on inserting the first two elements of the un- insertion sort is the ability to insert more than one item in their
ordered part into the ordered part during each iteration. This final correct positions in one sort trip (internal loop iteration).
idea earned slightly time efficient but the complexity of the al- Additionally, the inserted items will not suffer from shift-
gorithm still O(n2 ) [23] . However, all the cited previous works ing operations in later sort trips. Alongside, insertion into both
have shown a good enhancement in insertion sort algorithm ei- sorted sides can be run in parallel in order to increase the algo-
ther in worst case, in large array size or in very small array size. rithm performance (parallel work is out of scope of this paper).
In spite of this enhancement, a Quicksort algorithm indicates In case of ascending sort, BCIS initially assumes that the
faster results even for relatively small size array. most left item at array[1] is the left comparator (LC) where
In this paper, a developed in-place unstable algorithm is pre- is the left sorted part begin. Then inserts each element into
sented that shows fast performance in both relatively small size the left sorted part if that element less than or equal to the LC.
array and for high rate duplicated elements array. The proposed Correspondingly, the algorithm assumes the right most item at
algorithm Bidirectional Conditional Insertion Sort (BCIS) is array[n] is the right comparator (RC) which must be greater
well analyzed for best, worst and average cases. Then it is com- than LC. Then BCIS inserts each element greater than or equal
pared with well-known algorithms which are classical Insertion to the RC into the right sorted part. However, the elements that
Sort (IS) and Quicksort. Generally, BCIS has average time have values between LC and RC are left in their positions dur-
complexity very close to O(n1.5 ) for normally or uniformly dis- ing the whole sort trip. This conditional insertion operation is
tributed data. In other word, BCIS has faster average case than repeated until all elements inserted in their correct positions.
IS for both relatively small and large size array. Additionally, If the LC and RC already in their correct position, there are
when it compared with Quicksort, the experimental results for no insertion operations occur during the whole sort trip. Hence,
BCIS indicates less time complexity up to 70% -10% within the algorithm at least places two items in their final correct po-
the data size range of 32-1500. Besides, our BCIS illustrates sition for each iteration.
faster performance in high rate duplicated elements array com- In the pseudo code (part 1& 2), the BCIS algorithm is pre-
pared to the Quicksort even for large size arrays. Up to 10%- sented in a format uses functions to increase the clarity and
2
traceability of the algorithm. However, in statements (1 & 2) Algorithm BCIS Part 2 (Functions)
the algorithm initially sets two indexes, SL for the sorted left 44: function ISEQUAL(array, S L, S R)
part and SR for the sorted right part to indicate on the most left 45: for k S L + 1 to S R 1 do
item and the most right item respectively. 46: if array[k]! = array[S L] then
47: S WAP(array, k, S L)
Algorithm BCIS Part 1 (Main Body) 48: return k
1: S L le f t 49: end if
2: S R right 50: end for
3: while S L < S R do 51: return 1
4: SWAP(array, S R, S L + (S RS2
L)
) 52: . End the algorithm because all scanned items are equal
5: if array[S L] = array[S R] then 53: end function
6: if ISEQUAL(array, S L, S R)=-1 then 54: function InsRight(array, CurrItem, S R, right)
7: return 55: j SR
8: end if 56: while j right and CurrItem > array[ j] do
9: end if 57: array[ j 1] array[ j]
10: if array[SL] > array[SR] then 58: j j+1
11: SWAP (array, SL , SR) 59: end while
12: end if 60: Array[ j 1] CurrItem
13: if (S R S L) 100 then 61: end function
14: for i S L + 1 to (S R S L)0.5 do 62: function InsLeft(array, CurrItem, S L, le f t)
15: if array[SR] < array[i] then 63: j SL
16: SWAP (array, SR, i) 64: while j le f t and CurrItem < array[ j] do
17: else if array[SL] > array[i] then 65: array[ j + 1] array[ j]
18: SWAP (array, SL, i) 66: j j1
19: end if 67: end while
20: end for 68: Array[ j + 1] CurrItem
21: else 69: end function
22: i SL+1 70: function SWAP(array,i,j)
23: end if 71: T emp array[i]
24: LC array[S L] 72: array[i] array[ j]
25: RC array[S R] 73: array[ j] T emp
26: while i < S R do 74: end function
27: CurrItem array[i]
28: if CurrItem RC then
29: array[i] array[S R 1] replace it with LC. Otherwise, (if not found) all remaining ele-
30: INS RIGHT (array, CurrItem, S R, right) ments in the unsorted part are equal. Thus, the algorithm should
31: SR SR 1 terminate at the statement (7). Furthermore, this technique al-
32: else if CurrItem LC then lows equal elements array to sort in only O(n) time complexity.
33: array[i] array[S L + 1] Statements (4 & 13 20) do not have an effect on the correct-
34: INS LEFT (array, CurrItem, S L, le f t) ness of the algorithm, these statements are added to enhance
35: SL SL+1 the performance of the algorithm. The advantage of these tech-
36: ii+1 niques will be discussed in the analysis section (section-4).
37: else The while statement in (26) is the beginning of the sort trip,
38: ii+1 as mentioned previously, conditional insertions occur inside
39: end if this loop depending on the value of current item (CurrItem)
40: end while in comparison with the values of LC and RC. Insertion opera-
41: SL SL+1 tions are implemented by calling the functions INSRIGHT and
42: SR SR 1 INSLEFT.
43: end while
3. Example
The main loop starts at statements(3) and stops when the left
sorted part index (SL) reaches the right sorted part index (SR). The behavior of the proposed algorithm on an array of 15
The selection of LC and RC is processed by the statements elements generated randomly by computer is explained in Fig-
(4-25). In order to ensure the correctness of the insertion op- ure(1). In order to increase the simplicity of this example, we
erations LC must be less than RC, this condition processed in assumed the statements (4 & 13-20) do not exist in the algo-
statement (5). In case of LC equal to RC, the statement (6), us- rithm. For all examples in this paper we assumed as follows:
ing ISEQUAL function, tries to find an item not equal to LC and Items in red color mean these items are currently in process.
3
Bolded items represent LC and RC for current sort trip. Gray k k
+ T is ( ) + T is ( ) + 2(n 3k)
background means the position of these items may change dur- 2 2
ing the current sort trip. Finally, items with green background k k
+ + T is ( ) + T is ( ) + 2(n ik)
mean these items are in their final correct positions. 2 2
17 22 56 57 52 59 80 78 73 19 53 28 65 72 67 No insertion n
k
" # X
No insertion n k k
T (n) = T is ( ) + T is ( ) +
17 22 56 57 52 59 80 78 73 19 53 28 65 72 67
(n ik) (1)
17 22 56 57 52 59 80 78 73 19 53 28 65 72 67 No insertion k 2 2 i=1
17 22 56 57 52 59 80 78 73 19 53 28 65 72 67 No insertion
n2
" #
n k k
17 22 56 57 52 59 80 78 73 19 53 28 65 72 67 Insert into the right = T is ( ) + T is ( ) + n
k 2 2 k
17 22 56 57 52 59 72 78 73 19 53 28 65 67 80 Insert into the right " #
n k k
17 22 56 57 52 59 65 78 73 19 53 28 67 72 80 No insertion
= T is ( ) + T is ( ) + n n (2)
17 22 56 57 52 59 65 78 73 19 53 28 67 72 80 Insert into the right k 2 2
17 22 56 57 52 59 65 28 73 19 53 67 72 78 80 No insertion
Equation (2) represents a general form of growth function,
17 22 56 57 52 59 65 28 73 19 53 67 72 78 80 Insert into the right
it shows that the complexity of the proposed algorithm mainly
17 22 56 57 52 59 65 28 53 19 67 72 73 78 80 No insertion
depends on the value of k and the complexity of insertion func-
17 22 56 57 52 59 65 28 53 19 67 72 73 78 80 Insert into the left
tions.
End of first sort trip.
Figure 2: Best case example for array less than 100 elements
For this best case, we note that all insertions will be in the
left side only with one shifting operation per each insertion.
That means the cost of insertion each item is O(1). Therefor,
T (n) = C1 + C2 + C3
the total cost of the left insertion function is T is (n) = n. Also
n
+ (C3 + C4 + C5 + C6 + C7 + C8 + C21 + C22) all elements will inserted in one sort trip so that k = n .These
k values is substituted in equation(1) as follows:-
n
k
X
+ (C10 + C11 + C12 + C16 + C20) (n ik)
n
i=1 k
n X
+ (C13 + C15 C16 + C17 + C18 + C19)
n T (n) = [T is (n)] + (n ik)
k k i=1
!
+ C14 2
nk 3n n
+ C20n where k = n
16 8 k T (n) =n (14)
a = (C3 + C4 + C5 + C6 + C7 + C8 + C21 + C22)
b = C14 Hence, the best case of BCIS is O (n) for n < 100. Otherwise,
(for n 100) the loop started in statement (14) always prevents
c = (C10 + C11 + C12 + C16 + C20) this best case occurred because it only put LC and RC in their
d = (C13 + C15 C16 + C17 + C18 + C19) correct position and disallow insertions during all sort trips. As
e = C20 result, the loop in statement (14) forces the algorithm running
f = (C1 + C2 + C3) very slow on already sorted or revers sorted array.
n
Generally, already sorted and reverse sorted arrays are more
k
!
n nk 3n n X common in practice if compared with the above best case ex-
T (n) = a + b + + c (n ik) ample. Therefore, statement (4) has been added to enhance the
k 8 4 k i=1
n performance of best case and worst case when BCIS run on
+ d en + f sorted and revers sorted arrays. In case of already sorted array,
2
this statement makes the BCIS, during each sort trip, inserts
n2 n
! !
n nk 3n n
=a +b + +c half of (SR-SL) in least cost.
k 8 4 k 2k 2 The following example in Figure (3) explains how BCIS runs
n
+ d en + f on already sorted array. For simplicity not inserted elements are
2 not represented in each sort trip during the demonstration of this
example.
6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Original array. these values in equation(1) as follows :-
1 2 3 4 5 6 7 8 16 10 11 12 13 14 15 9 Statement 4. n
1st sort trip. k
1 2 3 4 5 6 7 8 16 10 11 12 13 14 15 9 n X
1 2 3 4 5 6 7 8 15 10 11 12 13 14 9 16 Insertions started. T (n) = [T is (n)] + (n ik)
1 2 3 4 5 6 7 8 14 10 11 12 13 9 15 16
k i=1
1 2 3 4 5 6 7 8 13 10 11 12 9 14 15 16
1 2 3 4 5 6 7 8 12 10 11 9 13 14 15 16 where k = n
1 2 3 4 5 6 7 8 11 10 9 12 13 14 15 16 n(n 1)
1 2 3 4 5 6 7 8 10 9 11 12 13 14 15 16 T (n) = (16)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Statement 4.
Hence, the worst case of BCIS is O(n2 ) for n < 100 . Like-
1 2 3 4 8 6 7 5 9 10 11 12 13 14 15 16 2nd sort trip. wise the situation in the best case, the loop in statement (14)
1 2 3 4 7 6 5 8 9 10 11 12 13 14 15 16 Insertions started. prevent the worst case happen because LC will not take the
1 2 3 4 6 5 7 8 9 10 11 12 13 14 15 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
second largest item in the array. Consequently, the worst case
of BCIS would be when it runs on reversely sorted array for
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Statement 10, no swap.
n 100. The following example explains the behaver of the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
BCIS on such arrays even the size of array less than 100.
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Original array.
Figure 3: Example of running BCIS on already sorted array
16 15 14 13 12 11 10 9 1 7 6 5 4 3 2 8 Statement 4.
16 15 14 13 12 11 10 9 1 7 6 5 4 3 2 8 Statement 11, swap.
8 15 14 13 12 11 10 9 1 7 6 5 4 3 2 16 1st sort trip.
For already sorted array, BCIS scans the first half consuming 1 8 14 13 12 11 10 9 15 7 6 5 4 3 2 16 Insertions started.
1 7 8 13 12 11 10 9 15 14 6 5 4 3 2 16
two comparisons per item (no insertions), then inserts the sec- 1 6 7 8 12 11 10 9 15 14 13 5 4 3 2 16
ond half of each sort trip consuming two comparisons per item 1 5 6 7 8 11 10 9 15 14 13 12 4 3 2 16
1 4 5 6 7 8 10 9 15 14 13 12 11 3 2 16
too. Because the sort trip size is repeatedly halved. Hence, it 1 3 4 5 6 7 8 9 15 14 13 12 11 10 2 16
1 2 3 4 5 6 7 8 15 14 13 12 11 10 9 16
can represent as following.
1 2 3 4 5 6 7 8 15 14 13 9 11 10 12 16 Statement 4
1 2 3 4 5 6 7 8 12 14 13 9 11 10 15 16 Statement 11, swap
n n n n
T (n) = 2 + 2 + 2 + 2 1 2 3 4 5 6 7 8 12 14 13 9 11 10 15 16 2nd sort trip
2 n 2 n 4 4 n 1 2 3 4 5 6 7 8 9 12 13 14 11 10 15 16 insertions begins
n 1 2 3 4 5 6 7 8 9 11 12 14 13 10 15 16
+ 2 + 2 + ..... + 2 i + 2 i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
8 8 2 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 No change required
stop when 2i = n = i = log n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
log
Xn n n
T (n) = (2 + 2 i ) = 4n (15) Figure 5: Example of running BCIS on reversely sorted array
i=1
2i 2
In case of reversely sorted array, BCIS does not insert the
Equations (14 & 15) represent the best case growth functions first half of the scanned elements, cost two comparisons per
of BCIS when run on array size less than 100 and greater than each element, then insert the second half reversely for each sort
and equal to 100 respectively. trip approximately. Considering the cost of reverse insertion
(for each sort trip) is T is (k) = k(k1) 2 where k halved repeatedly.
Like already sorted array analysis, the complexity of BCIS can
4.3. Worst Case Analysis be represented as follows.
n ( n )2 n2 n ( n4 )2 n4
The worst case happens only if all elements are inserted in T (n) = 2 + 2 + 2 +
one side in reverse manner during the first sort trip. This con- 2 2 4 2
dition provided when the RC and LC are the largest and second n ( 8n )2 n8
largest numbers in the array respectively, and all other items + 2 + + ........
8 2
are sorted in reverse order. The insertion will be in the left side
n ( 2ni )2 2ni
only. The following example in Figure(4) explains this worst + 2 i +
case when n < 100.
2 2
stop when 2i = n = i = log n
14 13 12 11 10 9 8 15 6 5 4 3 2 1 7 i=log
Xn n ( ni )2 ni
T (n) = 2 + 2
i
2
i=1
2 2
Figure 4: Worst case example for array less than 100 elements n2 3n
+ = (17)
6 2
Since each element in the this example inserted reversely, the Equations (16 & 17) represent the worst case growth func-
complexity of left insertion function for each sort trip equal to tions of BCIS when run on array size less than 100 and greater
T is (n) = n(n1)
2 . Also there is one sort trip so k = n, by substitute than and equal to 100 respectively.
7
5. Results and comparison with other algorithms sort a list of random data for some list sizes (X axis). Theoret-
ically, this ratio is equal to( BCIS total
IS total ) . In opposition, the exper-
The proposed algorithm is implemented by C++ using Net- imental ratio computed by divide BCIS time over IS time , when
Beans 8.0.2 IDE based on Cygwin compiler. The measurements these parameters represent experimental elapsed running time
are taken on a 2.1 GHz Intel Core i7 processor with 6 GB 1067 of BCIS and IS respectively.
MHz DDR3 memory machine with windows platform. Exper- In the experimental BCIS time
IS time ratio, we noticed that the pro-
imental test has been done on an empirical data (integer num- posed algorithm has roughly equal performance when com-
bers) that generated randomly using a C++ class called uni- pared to classical insertion sort for list size less than 50
IS time = 1). However, the performance of BCIS increased for
( BCIS
form int distribution. This class generates specified ranged of time
random integer numbers with uniform distribution[10]. larger list size noticeably. The time required to sort the same
size of list using BCIS begin in 70% then inclined to 4% of that
5.1. BCIS and classical insertion sort consumed by classical insertion sort for list size up to 10000.
Figure (8) explains the same ratio for n10000. This figure
Figure 6 explains the average number of comparisons and shows that BCIS t ime
IS t ime is decreased when the list size increased.
assignments (Y axis) for BCIS and IS with different list size For instance for the size 3,643,076 the experimental ratio equal
(X axis). The figure has been plotted using equations (3,4,10 to 0.00128 that means BCIS 781 times faster than IS.
& 11). This figure explains that the number of comparisons
In conclusion, Figures (7& 8) show that the theoretical an
and assignments of IS are approximately equal . In contrast,
experimental ratio are very close especially for large size lists.
in BCIS the number of assignments are less than the number of
This means BCIS go close to the best performance of average
comparisons. This feature show the better performance of BCIS
case for large size lists.
and support our claim that BCIS has less memory read/write
operations when compared with IS.
1.2000
1400000 0.8000
BCIS/IS
1200000
0.6000
Theoretical BCIS/IS
# of Comp. and Assign
1000000
Experimental BCIS/IS
0.4000
800000
0.2000
600000
400000
0.0000
1,102
32
41
54
71
93
121
159
209
275
363
479
632
834
1,457
1,926
2,546
3,366
4,450
5,884
7,780
200000
Array Size
0
0 500 1000 1500 2000 2500 Figure 7: BCIS/IS ratio for n < 10000
Array size
Experimental BCIS/IS
BCIS and IS which are measured by execution elapsed time,
0.0150
we represent these quantities as a theoretical and experimental
ratio of BCIS
IS . In theoretical ratio we assumed that the cost of an
0.0100
BCIS/QuickSort
Figure (9) explains a comparison in experimental perfor- 15
5,117
17,990
2,214
3,366
7,780
11,830
27,359
41,608
63,279
96,237
146,362
222,597
338,540
514,874
783,057
1,190,930
1,811,254
2,754,690
4,189,537
for some list sizes (X axis). We remarked that BCIS is faster
than Quicksort for list size less than 1500 for most cases. The
time required to sort the same size of list using BCIS ranged be- Array Size
tween 30% and 90% of that consumed by Quicksort when list
size less than 1500. Figure 10: BCIS/Quicksort for n > 2000
Although theoretical analysis in all previous cited works that
have been explained in literature (section-1) show that Quick- consumes only 50% to 90% of the time consumed by Quicksort
Sort has more efficient comparison complexity than BCIS. But when run on high rate of duplicated elements array. This vari-
experimentally BCIS defeats QuickSort for relatively small ar- ation in ratio is due to the random selection of LC and RC dur-
ray size for some reasons. First the low number of assign- ing each sort trip. The main factor that make BCIS faster than
ment operations in BCIS, second an assignment operation has Quicksort for such type of array is that there a small number
lower cost if compared with swap operation that used in Quick- of assignments and comparisons operations if there are many
Sort, whereas each swap operation requires three assignments numbers equal to LC or RC in each sort trip. This case could
to done. Finally, due to the nature of the cache memory occur with high probability when there is high rate of duplicated
architecture[18], BCIS uses cache memory efficiently because elements in array.
shifting operations only access to the adjacent memory loca-
tions while swap operations in QuickSort access memory ran- 1.2
domly. Therefore, QuickSort cannot efficiently invest the re- 1
markable speed gain that is provided by the cache memory.
BCIS/QuickSort
0.4
1.20000
0.2
1.00000 0
47,849
28
41
62
93
139
209
316
479
726
1,102
1,675
2,546
3,870
5,884
8,946
13,604
20,688
31,462
72,770
110,672
168,316
255,986
389,320
592,105
900,515
1,369,569
2,082,942
3,167,893
0.80000
BCIS/QuickSort
Array Size
0.60000
0.20000
6. Conclusions
0.00000
10
Sahin Emrah Amrahov received B.Sc.
and Ph.D. degrees in applied mathemat-
ics in 1984 and 1989, respectively, from
Lomonosov Moscow State University,
Russia. He works as Associate Professor at
Computer Engineering department, Ankara
University, Ankara, Turkey. His research
interests include the areas of mathematical
modeling, algorithms, artificial intelligence,
fuzzy sets and systems, optimal control, theory of stability and
numerical methods in differential equations.
11