



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















Step 1: [INITIALIZE] SET SMALL = ARR[K] Step 1: Repeat Steps 2 and 3 for K = 0 to N- Step 2: [INITIALIZE] SET POS = K Step 2: CALL SMALLEST(ARR, K, N,POS) Step 3: Repeat for J = K+1 to N -1 Step 3: SWAP A[K] with ARR[POS] IF SMALL > ARR[J] [END OF LOOP] SET SMALL = ARR[J] Step 4: Exit SET POS = J [END OF IF] [END OF LOOP] Step 4: RETURN POS
Step 1: Repeat Steps 2 to 5 for K = 1 to N โ 1
Step 2: SET TEMP = ARR[K]
Step 3: SET J = K - 1
Step 4: Repeat while TEMP <= ARR[J] and J>= SET ARR[J + 1] = ARR[J] SET J = J - 1 [END OF INNER LOOP] Step 5: SET ARR[J + 1] = TEMP
[END OF LOOP]
Step 6: EXIT
โ Merge sort is a sorting algorithm that uses the divide, conquer, and combine algorithmic paradigm. โ Divide means partitioning the n -element array to be sorted into two sub-arrays of n/2 elements. If A is an array containing zero or one element, then it is already sorted. However, if there are more elements in the array, divide A into two sub-arrays, A 1 and A 2 , each containing about half of the elements of A. โ Conquer means sorting the two sub-arrays recursively using merge sort. โ Combine means merging the two sorted sub-arrays of size n/2 to produce the sorted array of n elements.
Step 1: IF P < R
SET Q = (P + R)/
MERGE_SORT (ARR, P, Q)
MERGE_SORT (ARR, Q + 1, R)
MERGE (ARR, P, Q, R)
[END OF IF]
Step 2: END
The quick sort algorithm works as follows:
This is called the partition operation.
i = P - 1 For j = P to R - 1 { If ( ARR[ j ] <= X ) { i = i + 1 Exchange ARR[ i ] with ARR[ j ] } } Exchange ARR[ i + 1] with ARR[ R ] Return i + 1