The document provides pseudocode for several sorting algorithms:
1) Bubble sort compares adjacent elements and swaps them if they are in the wrong order until the list is fully sorted.
2) Insertion sort iterates through the list and inserts each element into its sorted position.
3) Shell sort improves on insertion sort by having elements jump distances farther than one position during sorting.
4) Merge sort divides the list into halves, recursively sorts them, and then merges the sorted halves back together.
5) Quicksort selects a pivot element and partitions the list into sublists based on element values relative to the pivot.
The document provides pseudocode for several sorting algorithms:
1) Bubble sort compares adjacent elements and swaps them if they are in the wrong order until the list is fully sorted.
2) Insertion sort iterates through the list and inserts each element into its sorted position.
3) Shell sort improves on insertion sort by having elements jump distances farther than one position during sorting.
4) Merge sort divides the list into halves, recursively sorts them, and then merges the sorted halves back together.
5) Quicksort selects a pivot element and partitions the list into sublists based on element values relative to the pivot.
The document provides pseudocode for several sorting algorithms:
1) Bubble sort compares adjacent elements and swaps them if they are in the wrong order until the list is fully sorted.
2) Insertion sort iterates through the list and inserts each element into its sorted position.
3) Shell sort improves on insertion sort by having elements jump distances farther than one position during sorting.
4) Merge sort divides the list into halves, recursively sorts them, and then merges the sorted halves back together.
5) Quicksort selects a pivot element and partitions the list into sublists based on element values relative to the pivot.
n = length(S) repeat swap = false for i = 1 to n -1 do if S[i-1] > S[i] then S[i-1] = temp temp = S[i] S[i] = S[i] -1 swap = true end if end for until not swap end function
Insertion Sort Pseudocode
Function insertionSort(S: array sort item) for i = 1 to length(A) j = i while j > 0 and S[j-1] > S[j] swap(S[j-1], S[j]) j = j-1 end while end for end function
shell sort pseudocode
gap = round (n/2) While gap > 0 for index = gap to n temp = array[index] subIndex = index while subIndex >= gap and array[subIndex gap] > temp array[subIndex] = array[subIndex gap] subIndex = subIndex gap array[subIndex] = temp gap = round(gap/2)
merge sort pseudocode if n <=1 return array middle = n/2 for index = 0 to middle - 1 leftArray[index] = array[index] for index = middle to n rightArray[index-middle] = array[index] left = mergeSort(left) right = mergeSort(right) return merge(left, right)
quick sort pseudocode
Quicksort(A as array, low as int, high as int) if (low < high) pivot_location = Partition(A,low,high) Quicksort(A,low, pivot_location - 1) Quicksort(A, pivot_location + 1, high)
Partition(A as array, low as int, high as int) pivot = A[low] leftwall = low
for i = low + 1 to high if (A[i] < pivot) then leftwall = leftwall + 1 swap(A[i], A[leftwall])