0% found this document useful (0 votes)
402 views5 pages

Merge Sort Algorithm Flowchart

The document describes the pseudocode for an in-place merge sort algorithm. It takes in an array and sorts it by recursively dividing it into halves, sorting each half, and then merging the sorted halves back together. It uses helper functions mergesort() and merge() to recursively divide and merge the sorted arrays.

Uploaded by

Harshit Malpotra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
402 views5 pages

Merge Sort Algorithm Flowchart

The document describes the pseudocode for an in-place merge sort algorithm. It takes in an array and sorts it by recursively dividing it into halves, sorting each half, and then merging the sorted halves back together. It uses helper functions mergesort() and merge() to recursively divide and merge the sorted arrays.

Uploaded by

Harshit Malpotra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Start

1
GET
numberOfElements

iter ← 1

Loop

Yes iter>numberOfEle
ments
No

1
GET arr[iter]

iter ← iter + 1

iter ← 1

Loop

Yes iter>numberOfEle
ments
No

PUT arr[iter] + " "

iter ← iter + 1

PUT ""¶

mergesort(arr, 1,
numberOfElements)

iter ← 1

Loop

Yes iter>numberOfEle
ments
No

PUT arr[iter] + " "

iter ← iter + 1

mergeSort.rap-main : page 1 : Harshit Malpotra : 76.54 mins, 15 saves


End

mergeSort.rap-main : page 2 : Harshit Malpotra : 76.55 mins, 15 saves


Start (in out arr, in s,
in end)

Yes No
s>=end

mid ← floor((s +
end) / 2)

mergesort(arr, s, mid)

mergesort(arr, mid +
1, end)

merge(arr, s, mid, mid


+ 1, end)

End

mergeSort.rap-mergesort : page 1 : Harshit Malpotra : 76.55 mins, 15 saves


Start (in out arr, in s1,
in e1, in s2, in e2)

i ← s1

j ← s2

k←1

Loop

Yes
i>e1 or j>e2
No

Yes No
arr[i]>=arr[j]

out[k] ← arr[j] out[k] ← arr[i]

j←j+1 i←i+1

k←k+1

Loop

Yes
i>e1
No

out[k] ← arr[i]

k←k+1

i←i+1

Loop

Yes
j>e2
No

out[k] ← arr[j]

mergeSort.rap-merge : page 1 : Harshit Malpotra : 76.55 mins, 15 saves


k←k+1

j←j+1

i ← s1

j←1

Loop

Yes j>length_Of(out) or
i>max(e1, e2)
No

arr[i] ← out[j]

i←i+1

j←j+1

End

mergeSort.rap-merge : page 2 : Harshit Malpotra : 76.55 mins, 15 saves

You might also like