Professional Documents
Culture Documents
3. EXCHS ← 0
5. If EXCHS = 0 then
Return
else LAST ← LAST – 1
6. Return
Time Complexity:
No. of Comparisons:
No. of Exchanges:
Insertion Sort
Time Complexity:
Merge Sort
The two tables in the current example could be stored in a common array K as
follows:
Procedure MERGE_SORT(K, FIRST, SECOND, THIRD)
1. I ← FIRST
J← SECOND
L← 0
3. If l ≥ SECOND then
Repeat while J ≤ THIRD
L← L + 1
TEMP [L] ← K[J]
J← J+ 1
else Repeat while l < SECOND
L← L + 1
TEMP [L] ← K[I]
I ← I+ 1
5. Return
Time Complexity:
T(n) = 2T(n/2) + θ(n)
Procedure TWO_WAY_MERGE SORT R(K, START, FINISH)
2. If SIZE ≤ 1 then
Return
7. Return
Call TWO_WAY_MERGE_SORT(K. 1. N)
Quick Sort or Partition Exchanged Sort
1. FLAG ← True
2. If LB < UB then
I← LB
J← UB + 1
KEY ← K[LB]
Repeat while FLAG
I←I+1
Repeat while K[I] < KEY
I←I+1
J←J ̶ 1
Repeat while K[J] > KEY
J← J ̶ 1
If I < J then
K[I] ↔ K[J]
else FLAG ← False
K[LB] ↔ K[J]
Call QUICK_SORT (K, LB, J ̶ 1)
Call QUICK_SORT (K, J + 1, UB)
3. Return
Heap Sort: