This action might not be possible to undo. Are you sure you want to continue?

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

9, December 2010

**Pair Wise Sorting: A New Way of Sorting
**

Md. Jahangir Alam 1, a, Muhammad Monsur Uddin2, b, Mohammad Shabbir Hasan3, c, Abdullah Al Mahmood4, c

E-mail: 1palash_14@yahoo.com, 2dolon_it@yahoo.com,3shabbir_cse03@yahoo.com, 4sajibcseofkuet@gmail.com a. Dhaka International University, Dhaka, Bangladesh b. Institute of Science, Trade and Technology, Dhaka, Bangladesh c. Panacea Research Lab, Dhaka, Bangladesh

Abstract— This paper presents a technique for sorting numerical data in an efficient way. The numbers of comparisons i.e. the running time of this technique is dependent on distribution or diversity of the value of data items as like as other efficient algorithms. When the total number of data is even, this method groups that data into a collection of pairs and therefore establishes the sorting constraints on each of the pairs. The control is traversed through the list of elements by changing the position of each pair which is the major principle of this technique. On the other hand, when the total number of elements is odd, this method sorts all elements except the last one in the same was as mentioned earlier and the last element is sorted using the general Insertion Sort. This algorithm is therefore a hybrid sorting method that sorts elementary numeric data in a faster and efficient manner. Keywords- Sorting, Pair Wise Sorting, Sorting Techniques.

II.

PROPOSED TECHNIQUE- PAIR WISE SORTING

The proposed sorting technique works in two different strategies depending on whether the number of elements to be sorted is odd or even. When the total number of data is even, this method groups that data into a collection of pairs and therefore establishes the sorting constraints on each of the pairs. The control is traversed through the list of elements by changing the position of each pair which is the major principle of this technique. On the other hand, when the total number of elements is odd, this method sorts all elements except the last one in the same was as mentioned earlier and the last element is sorted using the general Insertion Sort. This section describes the proposed sorting technique in details. A. Working Procedure: Let an array contains n elements where n is even. To sort these elements the proposed technique uses total phases

I.

INTRODUCTION

Sorting is a computational building block of fundamental importance and is one of the most widely studied algorithmic problems [1, 2]. The importance of sorting has also lead to the design of efficient sorting algorithms for a variety of fields like: parallel architectures [3], database systems [4], computer graphics and geographic information systems [5, 6], parallel programming patterns [7, 8] and so on. Many algorithms rely on the availability of efficient sorting routines as a basis for their own efficiency, and many other algorithms can be conveniently phrased in terms of sorting [9]. It is therefore important to provide efficient sorting routines on practically any programming platform. In this paper, we present a new sorting technique which is based on pair wise comparison. It works separately in two different situations: when total number of elements to be sorted is odd and when total number of elements to be sorted is even. This sorting technique has no major efficiencies over other already existing techniques. But its symmetric structure makes it simpler than other techniques. This paper is organized as follows. Section 2 describes the proposed technique in details, and the paper continues in Section 3 by calculating complexity of the proposed sorting technique. Section 4 compares the performance of the proposed technique with other already existing sorting techniques. We finish by drawing some broad and necessarily speculative and personal conclusions and future goal in Section 5.

where each phase contains two sub phases. The operations performed by two sub phases are different while the functions of all phases are identical. In the first sub phase the algorithm divides the n elements from position 1 to n into a total of pairs. The control moves

from first pair to the last pair and checks whether the first element of the pair is larger than the second one and if yes, then these elements are interchanged. In the second sub phase, (n-2) elements from position 2 to (n-1) are divided unto a total of

-1 pairs and the similar checking and swapping

occur as mentioned earlier. An additional check is maintained at the end of each phase to detect whether any swapping has occurred or not. If no interchange has been occurred, then the array is declared to be sorted and there is no need to continue for further phases. Otherwise, the phases are continued in the similar fashion till the final phase. Introduction of this checking may increase complexity as it requires initialization, changing and testing during the phases. But it is very effective for the cases where large numbers of elements are to be sorted and elements are uniformly distributed. This procedure indicates that the number of required phases is constant for a data set and it is half of the total number of

116

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 9, December 2010

elements. This algorithm is therefore very suitable for sorting large number of elements. B. Formulating Algorithm The proposed technique combines three functions: 1. PAIRWISE (A, N) 2. PROCESS (A, N) 3. INSERT (A, N) Where A is the array and N is the number of elements to be sorted. These functions are illustrated below: Algorithm: PAIRWISE (A, N) 1. [Initialize] Set oddEvenChk: = N mod 2 [Detects whether the array contains even number of elements or odd number of elements] 2. [Compare] if oddEvenChk = 0 then Call PROCESS (A. N) Else a. Call PROCESS (A, N-1) [Sorts the first N-1 elements] b. Call INSERT (A, N) [Sorts the last Nth elements] 3. Exit. Algorithm: PROCESS (A, N) //This function sorts array A with N elements where N is even. 1. [Initialize control variable] Set PTR: = 1 2. [Start of external loop] Repeat Steps from 3 to 8 While (PTR ≤ N/2) 3. [Initialize variable for first inner loop] Set START: =1, END: = N, FLAG: = 0 4. [Start of first inner loop] Repeat While (START < END) a. if A[START] < A [START+1] then: swap (A[START], A [START+1]) and Set FLAG: = FLAG+1. b. Set START: = START+2 [End of first inner loop] 5. [Initialize variable for second inner loop] Set START: =2, END: = N-1 6. [Start of second inner loop] Repeat While (START < END) a. if A[START] < A [START+1] then: swap (A[START], A [START+1]) and Set FLAG: = FLAG+1. b. Set START: = START+2 [End of second inner loop] 7. [Detect whether A is sorted or not] If FLAG = 0 then go to Step 9 8. [Increment counter for the external loop] Set PTR: = PTR+1 [End of external loop] 9. Exit

Algorithm: PROCESS (A, N) A is an array with N elements, where N-1 elements are sorted in increasing order. This function finds the actual position of the Nth element and inserts it into the array by the general insertion sort technique. As the technique is well known, hence it is not mentioned here. C. Example Figure 1 demonstrates an example where an array of eight (8) elements is sorted using the pair wise sorting technique. Here, Total number of elements, N = 8 Total number of phases = = =4

Number of comparisons in all passes are same and that is N-1 = 8-1 =7 In pair wise sorting technique, a flag can be used to cut down the passes, but no flag is used in this example. Total number of pairs in the first sub phase = = =4 -1= -1

Total number of pairs in the second sub phase = = 4-1 = 3

**Figure 1. Example of sorting an array of 8 elements with the proposed Pair Wise Sorting Technique
**

117 http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 9, December 2010

III.

COMPLEXITY ANALYSIS OF PAIR WISE SORTING

The proposed technique has a special feature that a number of unnecessary passes can be cu t down by using a flag variable. In this technique, the array can be sorted at any pass and not all time it is required to complete all of the passes. Flag variable is used for the purpose of reducing the total number of passes and therefore the total number of comparisons. So the total number of comparisons varies in two different cases: 1. Without a Flag Variable 2. With a Flag Variable A. Complexity Analysis: Without a Flag In this case, the first check is the one that determines whether the number of elements in the array is even or odd and depending on this, the next step is chosen. It requires a comparison at the very beginning. So, C1 = 1 Let, the number of elements in the array is n (1)

B. Complexity Analysis: With a Flag In this case also, the first check is the one that determines whether the number of elements in the array is even or odd and depending on this, the next step is chosen. It requires a comparison at the very beginning. So, C1 = 1 Let, the number of elements in the array is n When n is even: Number of comparisons in the first sub phase = Number of comparisons in the second sub phase = n>1 After each phase, there is a check to detect whether any interchange has been made or not. Hence, the total number of comparisons after each phase is: +( -1) + 1; when n>1 the total number of comparisons + n; where = is = -1; when (6)

When n is even: C2 = p * q Here, p = total number of passes = q = total number of comparisons ate each pass = + -1 (2) Therefore,

= n-1 Hence, from (2) we get C2 = When n is odd: For the last element, total comparisons will be, C3 = = = (4) = A control variable k is used for this odd-even checking. Hence, from equation (1), (3) and (4) we get, total number of comparisons when no Flag variable is used is: C = C1 + C2 + C3 = 1+ + , (5) When n is odd: For the last element, total comparisons will be, C3 = In average case, total number of comparisons, (3)

C2 =

118

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 9, December 2010

= = (8)

the proposed pair wise sorting technique is same as other sorting techniques for around 15000 data but it takes higher time with the increase in the number of elements to be sorted.

TABLE II. TIME REQUIRED BY EACH OF THE CANDIDATE METHODS FOR SORTING LARGE NUMBER OF RANDOM DATA Pair Wise Sort (Without Flag) 989.02 2307.67 3846.13 5669.34 7637.36 Time in Milliseconds (ms) Bubble Insertion Sort Sort 934.06 2142.86 3351.65 4780.22 6208.79 934.04 2087.91 3351.65 4270.33 6208.79 Quick Sort

A control variable k is used for this odd-even checking. Hence, from equation (6), (7) and (8) we get, total number of comparisons when no Flag variable is used is: C = C1 + C2 + C3 = 1+ + , (9)

Number of Elements

5000 10000 15000 20000 25000

879.12 1868.13 2857.14 3846.15 4835.17

IV.

COMPARISON WITH OTHER SORTING TECHNIQUES

The proposed technique has no major efficiencies over other sorting techniques rather it’s running time is a little bit higher than other techniques. It is just a new method that sorts numeric data. Its symmetric structure makes it simpler than other sorting techniques. Table 1 shows a comparison of average case complexity for the proposed technique and other already existing sorting techniques:

TABLE I. COMPARISON TABLE OF DIFFERENT SORTING TECHNIQUES IN

AVERAGE CASE COMPLEXITY

Sorting Technique Bubble Sort

Average Case Complexity =

Insertion Sort = Selection Sort = Quick Sort Merge Sort Heap Sort Pair Wise Sort (Proposed Technique) 1+ Without a Flag: + With a Flag: 1+ Here, + = = Figure 2. Performance graph

V.

CONCLUSION AND FUTURE WORK

is the number of elements to be sorted and

We compared the performance of the proposed pair wise sorting technique with other sorting techniques namely Bubble Sort, Insertion Sort and Quick Sort for sorting large number of random numeric data. The comparison was based on time required by each method for sorting these data. Table 2 and Figure 2 show the result. The results shows that performance of

The proposed pair wise sorting technique is a simple one based on odd-even strategy. We strongly believe that this strategy can be further used to develop techniques which will be more efficient. However, the limitation of the proposed technique is, it requires different approach for the last member of the array when the array contains odd number of elements. Most of the time, it is not required to complete all of the phases to sort elements. Here a flag is used to cut down the total number of phases. A flag is very useful for the cases when the elements of the array exist close to their exact positions. But the use of this flag causes the average number of comparisons to be higher than other algorithms. It would be best if it is possible to introduce a technique which will be able to sort elements efficiently without using a flag. This point will get our future focus. .

119

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

REFERENCES

[1] [2] [3] [4] [5] D. E. Knuth, The Art of Computer Programming, Volume 3: Sorting and Searching, Second ed. Boston, MA: Addison-Wesley, 1998. T. H. Cormen, C. E. Leiserson, R. L. Rivest, and C. Stein, Introduction to Algorithms, Second ed. MIT Press, Sep. 2001. S. G. Akl, Parallel Sorting Algorithms. Orlando: Academic Press, Inc., 1990. G. Graefe, “Implementing sorting in database systems,” ACM Comput. Surv., vol. 38, no. 3, pp. 1–37, 2006. C. Lauterbach, M. Garland, S. Sengupta, D. Luebke, and D. Manocha, “Fast BVH construction on GPUs,” in Proc. Eurographics ’09, Mar. 2009. V. Havran, “Heuristic ray shooting algorithms,” Ph.D. Thesis, Department of Computer Science and Engineering, Faculty of Electrical Engineering, Czech Technical University in Prague, Nov. 2000. J. Dean and S. Ghemawat, “MapReduce: Simplified data processing on large clusters,” Commun. ACM, vol. 51, no. 1, pp. 107–113, 2008. B. He, W. Fang, N. K. Govindaraju, Q. Luo, and T. Wang, “Mars: A MapReduce framework on graphics processors,” in Proc. 17th Int’l Conference on Parallel Architectures and Compilation Techniques, 2008, pp. 260–269. Nadathur Satish, Mark Harris, and Michael Garland, “Designing efficient sorting algorithms for manycore GPUs”, in Proc. 23rd IEEE International Parallel and Distributed Processing Symposium, May 2009, pp. 1-10. Mohammad Shabbir Hasan received his B.Sc. (Engg.) in Computer Science and Engineering from Khulna University of Engineering and Technology (KUET), Bangladesh in 2008. His research interest includes different areas of Software Engineering like Requirement Engineering, Software Metric, Software Security and Software Maintenance. He has coauthored numerous research papers published in International Journals and Conference Proceedings. Currently he is working as a researcher of Panacea Research Lab, Dhaka, Bangladesh. He is also a lecturer of Department of Computer Science and Engineering in Institute of Science, Trade and Technology, Dhaka, Bangladesh.

[6]

[7] [8]

[9]

AUTHORS’ PROFILE

Md. Jahangir Alam received his B.Sc. (Engg.) and M.Sc. in Computer Science and Engineering from Dhaka International University (DIU), Bangladesh. His research interests include Software Engineering and Data Structure. Currently he is working as a Senior Lecturer of Department of Computer Science and Engineering, Dhaka International University, Dhaka, Bangladesh.

Abdullah Al Mahmood received his B.Sc. (Engg.) in Computer Science and Engineering from Khulna University of Engineering and Technology (KUET), Bangladesh in 2009. His research interest includes Robotics, Artificial Intelligence, Internet Security and various areas of Software Engineering like Requirement Gathering, Requirement Prioritization and Software Security. He has coauthored a good number of research papers published in International Journals and Conference Proceedings. Currently he is working as a researcher of Panacea Research Lab, Dhaka, Bangladesh. He is also a lecturer at Institute of Science, Trade and Technology, Dhaka, Bangladesh and a Project Coordinator of Technocrats BD.

Muhammad Monsur Uddin received his B.Sc. (Engg.) in Computer Science and Engineering from Institute of Science, Trade and Technology (ISTT), Dhaka, Bangladesh. His research interests include Software Engineering and Data Structure.

120

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

This paper presents a technique for sorting numerical data in an efficient way. The numbers of comparisons i.e. the running time of this technique is dependent on distribution or diversity of the v...

This paper presents a technique for sorting numerical data in an efficient way. The numbers of comparisons i.e. the running time of this technique is dependent on distribution or diversity of the value of data items as like as other efficient algorithms. When the total number of data is even, this method groups that data into a collection of pairs and therefore establishes the sorting constraints on each of the pairs. The

control is traversed through the list of elements by changing the position of each pair which is the major principle of this technique. On the other hand, when the total number of elements is odd, this method sorts all elements except the last one in the same was as mentioned earlier and the last element is sorted using the general Insertion Sort. This algorithm is therefore a hybrid sorting method that sorts elementary numeric data in a faster and efficient manner.

control is traversed through the list of elements by changing the position of each pair which is the major principle of this technique. On the other hand, when the total number of elements is odd, this method sorts all elements except the last one in the same was as mentioned earlier and the last element is sorted using the general Insertion Sort. This algorithm is therefore a hybrid sorting method that sorts elementary numeric data in a faster and efficient manner.

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue listening from where you left off, or restart the preview.

scribd