Professional Documents
Culture Documents
: 5
Write a program to do a bubble sort on an array.
PSEUDO CODE:
SUBROUTINE mergeSort(array)
If len(array) > 1 Then
# This is the point where the array is divided into two subarrays
halfArray = len(array) / 2
FirstHalf = array[:halfArray]
# The first half of the data set
SecondHalf = array[halfArray:]
# The second half of the data set
k=0
outputList(array)
ENDSUBROUTINE
SUBROUTINE outputList()
FOR i in len(array)
OUTPUT array[i]
ENDFOR
ENDSUBROUTINE
int k;
i = 0;
j = 0;
k = p;
while (i < n1 && j < n2)
{
if (L[i] <= M[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = M[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
COMPLEXITY: O(n*log n)