# Chunk Sort

Document Sample

```					                                                          (IJCSIS) International Journal of Computer Science and Information Security,
Vol. 8, No. 4, July 2010

Chunk Sort

Syed Zaki Hassan Kazmi                                                        Syeda Shehla Kazmi
Department of Computer Science                                          Department of Computing & Mathematics
IQRA University Islamabad Campus                                           Manchester Metropolitan University,
Pakistan                                                                 United Kingdom
zaki.mzd@gmail.com                                                       shehla_kazmi@hotmail.com

Syeda Sobia Hassan Kazmi                                                    Syed Raza Hussain Bukhari
Department of Computer Science                                              Department of Computer Science
The University Of Azad Jammu And Kashmir                                    The University Of Azad Jammu And Kashmir
fajar_zara@hotmail.com                                                     razabukhari@hotmail.com

Abstract—the objective of this paper is to develop new efficient            consume a substantial time in ordering the data. The
sorting technique known as Chunk Sort. Chunk sort is based                  computational problems always have a cumbersome effect
on the idea of Merge Sort. In this sort divide main data list into          on the researchers on one hand and open the opportunities
number of sub list then sort sub list and combine them until                for them on the other hand.
the whole list become sorted. The difference between merge
sort and chunk sort is, merge sort merge two sub list in to one,
The study in hand proposes a new sorting technique that
but chunk sort merge three sub list in to single sorted list. It is         is tested and analyzed against merge sort and quick sort to
fast then many existing sorting techniques including merge sort             provide its efficiency.
and quick sort. Running Cost analysis and the result obtained                   This paper is organized as follows; Section II presents a
after implementation are provided in the graphical form with                brief review of existing sorting algorithms. Section III
an objective to compare the efficiency of the technique with                presents the description of proposed solution. Section IV
quick sort and merge sort, as both are consider as efficient and            presents the proposed algorithm. Section V presents
fast one.                                                                   Running Cost Analysis. Section VI present comparison
between chunk sort with merge sort and quick sort. Section
Keywords-Sorting;Merge Sort; Quick Sort.
VII ends with concluding remarks.
I.     INTRODUCTION                                           II.   A BRIEF REVIEW OF EXISTING SORTING
Algorithms have a vital and key role in solving the                                           ALGORITHMS
computational problems, informally an algorithm is a well                       A number of sorting techniques are currently used in the
defined computational procedure that takes input and                        field of computer science. This section will briefly discuss
produces output. Algorithm is a tool or a sequence of steps                 some of the trendy sorting techniques among them. These
to solve the computational problems [1].                                    are following:
An Algorithm is a step by step process to solve a
A. Merge Sort
particular problem in a finite amount of time and has a
fundamental and key role in solving the computational                           Merge sort is an O (n log n) sorting algorithm. It belongs
problems. Informally an algorithm is a well-defined                         to the family “Sorting by Merging”. It is an example of the
computational procedure that takes input and produces                       divide and conquer algorithmic paradigm. It was proposed
output. So a Sorting Algorithm is the step by step process by               by John von Neumann in 1945 (Cormen T. H, Leiserson C.
E., Rivest R. L. and Stein C. [1990] 2001). Conceptually, a
which data is organized into a particular increasing or
merge sort works as follows:
decreasing order, i.e. in ascending and descending order.
1. If the list is of length 0 or 1, then it is already
Data can be in numerical or character form in particular and                         sorted. Otherwise:
can be in other forms as well. There are a lot of sorting                        2. Divide the unsorted list into two sublists of about
techniques, currently used in industry and academia, to                              half the size.
arrange the data of various forms and from different areas.                      3. Sort each sublist recursively by re-applying merge
Sorting is of substantial importance as the human is                                 sort.
obsessed in keeping the ordered information/knowledge. To                        4. Merge the two sublists back into one sorted list.
search the particular data efficiently the arrangement of data
is very important. To facilitate the human, computers

ISSN 1947-5500
(IJCSIS) International Journal of Computer Science and Information Security,
Vol. 8, No. 4, July 2010

B.    Quick Sort                                                                  sqrr = 1
p2 = 0
Quick sort is another well-known sorting algorithm and
while sqrr != l
base on divide-and-conquer paradigm. Its worst-case                               {
running time is Θ(n²) having a list of n items. In spite of                         p1 = 0
slow worst-case running time, quick sort is often the best                          p3 = 0
practical choice for sorting the lists because it is extremely                      while p3 < l
efficient on the average running time i.e. Θ(nlogn). In most                        {
real-world data it is possible to make design choices which                            r=2
minimize the probability of requiring quadratic time                                   p3 = p3 + sqr
(Cormen T. H, Leiserson C. E., Rivest R. L. and Stein C.                               if p3 > l
{
Quicksort 2001).
p3 = l
III.   CHUNK SORT                                                }
while p2 != p3 - 1
Chunk sort is based on the idea of Merge Sort. In this sort                        {
divide main data list into number of sub list then sort sub list                          p4 = p2 + 1
and combine them until the whole list become sorted. The                                  p2 = p2 + sqrr
difference between merge sort and chunk sort is, merge sort                               if p2 >= p3
merge two sub list in to one, but in chunk sort merge three                               {
sub list in to single sorted list. It is fast then many existing                             p2 = p3 - 1
sorting techniques including merge sort and quick sort.                                   }
Conceptually, a Chunk sort works as follows:                                              if r % 2 == 0
1. If the list is of length 0 or 1, then it is already                               {
sorted. Otherwise:                                                                 if arr[p1] >= arr[p2]
2. Divide the unsorted list into three sublists.                                        {
r=r+1
3. Sort each sublist.
j = p1
4. Merge the three sublists back into one sorted list.
for k = p4; k <= p2; k++
{
temp[j] = arr[k]
j++
}
x = p1
while x != p4
{
temp[j] = arr[x]
x++
j++
}
}
else
{
If arr[p4]<arr[p4-1]
{
r=r+1
j=p1
x=p4
for k = p1; k <= p2; k++
{
if arr[j] <= arr[x]
{
temp[k] = arr[j]
j++
if j == p4
IV.   ALGORITHM : PSEUDO CODE                                                            {
Square Root Sort (arr)                                                                                 k++
temp = temperary Array                                                                         while k <= p2
l = length[arr]                                                                                 {
length = l                                                                                        temp[k] = arr[x]
t=l/4                                                                                             x++
sqr = 3                                                                                           k++

ISSN 1947-5500
(IJCSIS) International Journal of Computer Science and Information Security,
Vol. 8, No. 4, July 2010

} }}                                                                   {
else                                                                             arr[k] = arr[x]
{                                                                                x++
temp[k] = arr[x]                                                              if x > p2
x++                                                                           {
if(x>p2)                                                                         k++
{                                                                                while k <= p2
k++                                                                           {
while k<=p2
{                                                                                  arr[k] = temp[j]
j++
temp[k] = arr[j]                                                                k++
j++                                                                         }
k++
} }}}}}}                                                                   }

else                                                                                        }
{
if temp[p1] >= arr[p2]                                                          }
{
r = r + 1;                                                               }
j = p1
for k = p4; k <= p2; k++                                                 else
{                                                                        {
arr[j] = arr[k]                                                          r=r+1
j++                                                                      for k = p1; k <p4; k++
}                                                                           {
x = p1                                                                         arr[k] = temp[k]
while x != p4
{                                                                            }
arr[j] = temp[x]
x++                                                                   }
j++                                                               }

}                                                                }
}
else                                                             }
{                                                                if r % 2 != 0 && p1 != p2
{
if arr[p4] < temp[p4 - 1]                                         for j = p1; j <= p2; j++
{                                                                 {
r=r+1
j = p1                                                             arr[j] = temp[j]
x = p4
for k = p1; k <= p2; k++                                      }
{                                                           }
if temp[j] <= arr[x]                                     p1 = p2 + 1
{                                                        p2 = p1 + sqrr - 1
arr[k] = temp[j]
j++                                                }
if j == p4                                         sqrr = sqr
{                                                  p2 = sqrr - 1
k++
while k <= p2                                   if sqr >= t
{                                              {
arr[k] = arr[x]                                 sqr = l
x++                                          }
k++                                          else
}                                              {
}                                                     sqr = sqr * 3
}                                                      }
else                                           }

ISSN 1947-5500
(IJCSIS) International Journal of Computer Science and Information Security,
Vol. 8, No. 4, July 2010

V.     RUNNING COST ANALYSIS                                         It can be observed from the Table 1 and graph
In order to get a better handle of what the resulting                                        presented in Figure 1 that performance of proposed
complexity might be, suppose that we denoted by T(n) the                                          algorithm (Chunk Sort) is far better than the Quick Sort and
amount of time that Chunk Sort uses on an array of size n.                                        Merge Sort.
Recall that executing a sequence of instructions will cause
Table 2 shows the comparison of the proposed
us to add the running time. Hence, the running time will
algorithm (Chunk Sort) with the traditional sorting
obey the following equation:
algorithms on the basis of execution time when input data
T(n) = T(n/3)+ T(n/3)+ T(n/3)+Tmerge(n) = 3T(n/3)+cn
list is in ascending order. Graphical view of the same
where c is a constant, reflecting the actual number of
analysis is presented in the Figure 2
basic operations (comparisons, tests, arithmetic operations,
assignments) in the merge routine. we would like to get a
closed formula for T, or at least figure out what its fastest-
growing term is (so that we can figure out O() for the
algorithm).To get a better grip on the problem, let us
unwind T for a couple more steps:
T(n) = 3T(n/3)+cn
T(n) = 3(3T(n/9)+cn/3)+cn=32 T(n/9)+2cn
T(n) = 32 (3T(n/27)+cn/9)+cn=32 T(n/27)+3cn                                                                                       Table 2: Chunk Sort v/s Merge Sort and Quick Sort
How many times can we continue this expansion?
Until we get to T(1) which is 1(this corresponds to the base
case of running on an array of size 1). Since in each step we                                                             45000
divide n, we will reach T(1) is log3 n steps. At that point,                                                              40000
we will have:                                                                                                             35000
T(n) = 2log3 nT(1)+cn log3 n                                                                                              30000
Execution Time(ms)

Square Root Sort
The first term above is O(n), the second is O(n log3 n),                                                             25000
Merge Sort
so the whole algorithm is                                                                                                 20000
15000                                             Quick Sort
T (n) = O(n log3 n)                                                                                   10000
VI.                    COMPARISON OF CHUNK SORT WITH MERGE SORT                                                         5000
AND QUICK SORT
0

Table 1 show the comparison of the proposed algorithm
0

0
00
0

00

00
00

00

00

00
10

(Chunk Sort) with the traditional sorting algorithms on the
50

20

40

basis of execution time when input data list is in descending                                                                                 No. of Elements

order. Graphical view of the same analysis is presented in
the Figure 1.
Figure 2: Chunk Sort v/s Merge Sort and Quick Sort
It can be observed from the Table 2 and graph presented
in Figure 2 that performance of proposed algorithm (Chunk
Sort) is far better than the Quick Sort and Merge Sort.

Table 3 shows the comparison of the proposed algorithm
Table 1: Chunk Sort v/s Merge Sort and Quick Sort                  (Chunk Sort) with the traditional sorting algorithms on the
basis of execution time when input data list is generated by
50000                                                                      random numbers. Graphical view of the same analysis is
Execution Time(ms)

40000                                         Square Root Sort             presented in the Figure 3.
30000                                         Merge Sort
20000
10000                                         Quick Sort
0
00
0

0

0
00

00

00
00
10

00

00
50

20

40

No. of Elements

Table 3: Chunk Sort v/s Merge Sort and Quick Sort
Figure 1: Chunk Sort v/s Merge Sort and Quick Sort

ISSN 1947-5500
(IJCSIS) International Journal of Computer Science and Information Security,
Vol. 8, No. 4, July 2010

[8] Cormen T. H, Leiserson C. E., Rivest R. L. and Stein C. [1990] (2001).
“Introduction to Algorithms”, 2nd edition, MIT Press and McGraw-
Hill, ISBN 0-262-03293-7, pp. 27–37. Section 2.3: Designing
80000                                                                        algorithms.
70000                                                                   [9] Cormen T. H, Leiserson C. E., Rivest R. L. and Stein C. (2001).
60000                                                                        “Introduction to Algorithms”, 2nd edition, MIT Press and McGraw-
Execution Time(ms)

Square Root Sort
50000                                                                        Hill, ISBN 0-262-03293-7, pp. 145-149. Section 7.1: Quick Sort.
40000                                      Merge Sort                   [10] Cook C. R., Kim D. J. (1980) “Best Sorting Algorithms for Nearly
30000                                                                        Sorted Lists”, Communication of ACM, Vol. 11, Issue 11, pp 620-624.
20000                                      Quick Sort                   [11]Wainwright R.L. (1985) “A Class of Sorting Algorithms based on
10000                                                                        Quick Sort”, Communication of ACM, Vol. 28, Issue 4, pp 396-402.
0
0

0
00
0

00

00
00

00

00

00
10

50

20

40

No. of Elements

Figure 3: Chunk Sort v/s Merge Sort and Quick Sort
It can be observed from the Table 6.8 and graph
presented in Figure 6.11 that performance of proposed
algorithm (Chunk Sort) is far better than the Quick Sort and
Merge Sort.
VII. CONCLUSION
By analyzing the graphs above, it can be easily
examined that Chunk Sort is efficient then merge sort and
quick sort. In future, we are foreseeing to come up with a
new sorting technique, which hopefully will be more
efficient.
ACKNOWLEDGMENT
We acknowledge the support and contribution from our
loving and caring families, teachers and friends in
continuing the education and research. With their moral and
financial support, we are in higher education, which
encourages us to write this research for the ease of human
kind. Thank you all.
REFERENCES
[1] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and
Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press
and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 1.1:
Algorithms, pp.5–6.
[2] Knuth D. (1997) “The Art of Computer Programming, Volume 3:
Sorting and Searching’’, Third Edition. Addison-Wesley, 1997. ISBN
0-201-89685-0.
[3] Philippas T., Yi Z. (2003), “A Simple, Fast Parallel Implementation of
Quicksort and its Performance, Evaluation on SUN Enterprise
10000”. IEEE- Euro micro Conference on Parallel, Distributed and
Network-Based Processing (Euro-PDP’03). ISBN: 0-7695-1875-3/03
[4] Iqbal Z., Gull H. and Muzaffar A. W. (2009) “A New Friends Sort
Algorithm”. 2nd IEEE International Conference on Software
Engineering and Information Technology, ISBN 978-1-4244-4520-2,
pp 326-329.
[5] Merritt S. M. (1985), “An inverted taxonomy of Sorting Algorithms”.
ACM Journal, Programming Techniques and Data Structures, Vol. 28,
Number 1.
[6] Green, C., Barstow. D. (1978), “On program synthesis knowledge”.
Artif. Infd. 10, pp. 241-279.
[7] Hildebrandt P. and Isbitz H. (1959) “Radix Exchange—An Internal
Sorting Method for Digital Computers”. Journal of the ACM Volume
6, Issue 2, ISSN: 0004-5411 pp: 156 – 163.