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

1 - (Bubble Sort)

The document discusses different sorting algorithms including bubble sort, insertion sort, merge sort, quick sort, selection sort, and shell sort. It provides pseudocode to demonstrate the process for each algorithm.

Uploaded by

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

1 - (Bubble Sort)

The document discusses different sorting algorithms including bubble sort, insertion sort, merge sort, quick sort, selection sort, and shell sort. It provides pseudocode to demonstrate the process for each algorithm.

Uploaded by

Nahom Endale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

1-(Bubble Sort)

FOR each element of the list

FOR each element of the list

IF current element greater then next element

swap the elements

END IF

END FOR

END FOR

2-(Insertion Sort)

FOR each element of the master list

Extract the current item

Locate the position to insert by comparing with items from sub-list

Insert the item to the position

END FOR
3-(Merge Sort)

PROCEDURE function mergeSort

FOR each element of the master list indexed by i

if ( i <= 1 ) return a

var left = a[0] to a[i/2]

var right = a[i/2+1] to a[i]

left = mergeSort( left )

right = mergeSort( right )

return merge( left,right )

END FOR

END PROCEDURE

PROCEDURE function mergeSort

WHILE length(left) > 0 and length(right) > 0

if first(left) ≤ first(right)

append first(left) to result

left = rest(left)

else

append first(right) to result

right = rest(right)
IF length(left) > 0

append left to result

END IF

IF length(right) > 0

append right to result

END IF

return result

END PROCEDURE

4-(Quick Sort)

PROCEDURE function quickSort

IF list is empty

Return the list

END IF

Choose first element as the pivot

FOR each element of the list start from position 1

IF element is greater than pivot

Assign it to the left side

ELSE

Assign it to the right side


END IF

END FOR

return quickSort(left)+pivot+quickSort(right)

END PROCEDURE

5-(Selection Sort)

FOR each element of the master list indexed by i

Set current element of master list as the sub-list[i] element

Find the smallest item from the master list (staring from i)

Swap it with the last element of sub-list

END FOR

6-(Shell Sort)

Caculate gap size ($gap)

WHILE $gap is greater than 0


FOR each element of the list, that is $gap apart

Extract the current item

Locate the position to insert

Insert the item to the position

END FOR

Calculate gap size ($gap)

END WHILE

You might also like