Professional Documents
Culture Documents
Indexed Array Algorithm For Sorting
Indexed Array Algorithm For Sorting
Authorized licensed use limited to: Ingrid Nurtanio. Downloaded on October 01,2020 at 02:21:12 UTC from IEEE Xplore. Restrictions apply.
Now the shorter form of the algorithm can be stated as 2. As the percentage of sorted data increases in the array
follows: number of memory writes required also decreases
IAS ( A[ ], n ) ( )
compared to other existing O n 2 algorithm.
1. j ← 0, B[j] ← 0
2. for i ← 1 to n III. CORRECTNESS OF THE ALGORITHM
3. do if(B[j] <= i)
4. j←0
5. B[j] ← i Theorem – The necessary and sufficient condition for an
6. for k ← i to n array a[max] to be sorted is for any indices p and q, p ≤ q ↔
7. INSERT(k, B[],j+1) A[p] ≤ A[q] where p, q ∈[1 , n].
8. else We now prove that after completion of algorithm, resultant
9. for k ← B[j+1] to n array satisfies the above condition.
10. INSERT(k, B[],j+1)
11. EXCHANGE(A[], i , B[j]). Proof:- We would use loop invariant method to prove
12. do if(B[j] > 1) correctness of IAS ( ). We would use its shorter form for
13. j←j–1 reference.
Loop invariant: Before and after each iteration the sub
The working of the above algorithm can be understood by the array A[(q+1)…….(p – 1)] is sorted.
following example. Consider the following input array:
7 8 5 3 9 15 6 1 10 2 • Initialization:
In this part we take an array B and initialize its first
Array A and B (used to save indices of array A, which element with 0. Hence loop invariant holds before the first
will be used in sorting) during n iterations of INSERT loop iteration.
function after line - 7 is as follows:
A[] B[] • Maintenance:
Here starting with B[0]=0 now in lines 6-9 we store the
7 8 5 3 9 15 6 1 10 2 0 index of element in B[j]which is lesser than element at the
7 8 5 3 9 15 6 1 10 2 0 2 index of A stored in B[j-1]. Now after storing indices in array
7 8 5 3 9 15 6 1 10 2 0 2 3 B we exchange A[i] ↔ A[B[j]], this makes smallest element
7 8 5 3 9 15 6 1 10 2 0 2 3 7 in subarray A[i…..n] placed to its required position i.e. at
A[i]. For the next invariant to find the smallest element in
Now we show the array status after lines 14, for each further array we use B[j-1]. Hence the loop invariant holds.
iteration of the outermost for loop. After each iteration the Hence the loop invariant is maintained for each iteration of
element at indices stored at end of array B and element at the for loop.
indices i are exchanged.
• Termination:
A[] B[] It remains to note that when the outer loop terminates, i=
length(A)+1 so A[0….i-1] is A[0….length] and thus from the
1 8 5 3 9 15 6 7 10 2 0 2 3 9 reasoning of the maintenance part, we can infer that at the
1 2 5 3 9 15 6 7 10 8 0 2 3 end of this iteration the A[1………length] is sorted. Hence
1 2 3 5 9 15 6 7 10 8 3 loop invariant holds at termination of the algorithm also.
1 2 3 5 9 15 6 7 10 8 4 6
1 2 3 5 6 15 9 7 10 8 5 6 7 Hence, we prove that the algorithm IAS ( ) correctly sorts
1 2 3 5 6 7 9 15 10 8 5 6 9 the input array.
1 2 3 5 6 7 8 15 10 9 7 8 9
1 2 3 5 6 7 8 9 10 15 8
Completely sorted data after all iterations :- IV. COMPLEXITY OF THE ALGORITHM
35
Authorized licensed use limited to: Ingrid Nurtanio. Downloaded on October 01,2020 at 02:21:12 UTC from IEEE Xplore. Restrictions apply.
IAS ( A[ ], n ) cost times V. APPLICATIONS
1. j ← 0, B[j] ← 0 c1 1
The present algorithm can be efficiently used to sort small
2. for i←1 to n c2 n arrays, typically of size lying from 10 – 50 elements. The
3. do if(B[j] <= i) c3 1 algorithm can be used in conjunction with the O(n log n )
4. j←0 sorting algorithms efficiently.
5. B[j] ← i Our algorithm can also be used efficiently in all the places
6. for k ← i to n where percentage of sorted data in input data elements is
high. This algorithm can be used to find percentage of sorted
7. do if (A[k] <= A[B[j]]) c4 n
data in input data set by checking the extent of indexing in
8. j←j+1 array B.
9. B[j] ← k In the single-objective optimization there is only one
10. else c5 1 global optimum, but in multiobjective optimization there is a
11. for k ← B[j+1] to n set of solutions, called the Pareto-optimal(PO) set, which are
12. do if(A[k] <= A[B[j]]) considered to be equally important; all of them constitute
global optimum solutions. An important goal in
13. j←j+1 c6 n multiobjective optimisation is to find a good set of non-
14. B[j] ← k . dominated solutions that is both well-distributed and well-
15. exchange A[i] ↔ A[B[j]] c 1 converged. Since we are storing indices of smaller elements
16. do if(B[j] > 1) c87 1 with respect to pivot element, so this stored data can be used
17. j ← j – 1 in finding a measure of the amount of domination and in non-
We can aggregate the constants into singular constants, dominated sorting to find set of dominating elements and
without the loss of generality, thus making the derivation dominated elements.
more comprehendable. Hence we compute f (n) by
multiplying the costs with corresponding times. So we have, VI. CONCLUSION AND FUTURE WORK
36
Authorized licensed use limited to: Ingrid Nurtanio. Downloaded on October 01,2020 at 02:21:12 UTC from IEEE Xplore. Restrictions apply.