



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Includes Bubble sort, Insertion Sort etc
Typology: Slides
1 / 27
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