




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
The pseudocode for various sorting algorithms including Bubble Sort, Modified Bubble Sort, Insertion Sort, Selection Sort, Merge Sort, Heap Sort, and Quicksort. Each algorithm is presented with its corresponding pseudocode.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!
for i = n downto 2 do for j = 1 to i-1 do if A[j] > A[j+1] then A[j] ↔ A[j+1] end if end for end for
for i = n downto 2 do for j = 1 to i-1 do if A[j] > A[j+1] then A[j] ↔ A[j+1] end if end for end for
i ← n- while i > 0 do t ← 1 for j = 1 to i do if A[j] > A[j+1] then A[j] ↔ A[j+1] t ← j end if end for i ← t- end while
for i = 2 to n do t ← A[i] j ← i- while j>0 and A[j]>t do A[j+1] ← A[j] j ← j- end while A[j+1] ← t end for
for i = 2 to n do t ← A[i] j ← i- while j>0 and A[j]>t do A[j+1] ← A[j] j ← j- end while A[j+1] ← t end for
for i = n downto 2 do k ← 1 for j = 2 to i do if A[j] > A[k] then k ← j end for A[k] ↔ A[i] end for
for i = n downto 2 do k ← 1 for j = 2 to i do if A[j] > A[k] then k ← j end for A[k] ↔ A[i] end for
proc heapsort(A: list, n: list size) {Create heap} for r = bn/2c downto 1 do sift(r,n) end for {Finish Sort} for m = n downto 2 do A[1] ↔ A[m] sift(1,m-1) end for end proc
proc sift(p: root, m: size of list) c ← 2p while c ≤ m do if c < m then if A[c+1] > A[c] then c ← c+1 end if end if if A[c] > A[p] then A[p] ↔ A[c] p ← c c ← 2p else exit while loop end if end while end proc
procedure quicksort(A,p,r) if p<r then q ← partition(A,p,r) quicksort(A,p,q-1) quicksort(A,q+1,r) end if end procedure
function partition(A,p,r) X ← A[r] i ← p- for j = p to r-1 do if A[j] ≤ X then i ← i+ A[i] ↔ A[j] end if end for A[i+1] ↔ A[r] return(i+1) end function