ScholarMatic | 24/7 Homework Help

ScholarMatic Will Help You Write Your Essays and Term Papers

Answered » You can buy a ready-made answer or pick a professional tutor to order an original one.

Sorting Algorithms & Analysis

by | Nov 30, 2023 | questions

Task is in “Outline.pdf”
Note: I have done parts of two questions that you can use if you like. This is in “Assignment 2 – Part 1.docx”

Document Preview:

Assignment 02: Part I
Question 1:
Bubble sort in ascending order.
Pseudo code:
FUNCTION BubbleSort IMPORT array EXPORT array
FOR pass ??0 TO (array.length–1)-1 DO ?Need N-1 passes to guarantee sorted
FOR ii ??0 TO (array.length–1 – pass)-1 DO ?NOTE: 0-based array indexing
IF (array[ii] > array[ii+1]) THEN ?Avoid >= to keep the sort stable
temp ??array[ii] ?Swap out-of-order elements ii and ii+1
array[ii] ??array[ii+1]
array[ii+1] ??temp
ENDIF
ENDFOR
ENDWHILE
Quick sort in ascending order, with partition choosing pivot in the middle of the sub-array.
Pseudo code:
FUNCTION QuickSort IMPORT array, leftIdx, rightIdx EXPORT array
IF (rightIdx > leftIdx) THEN ?Check that the array is > one element in size
pivotIdx ??(leftIdx+rightIdx) / 2 ?Pivot selection strategy: middle element
newPivotIdx ??doPartitioning(array, leftIdx, rightIdx, pivotIdx)
QuickSort(array, leftIdx, newPivotIdx-1) ?Recurse: Sort left partition
QuickSort(array, newPivotIdx+1, rightIdx) ?Recurse: Sort right partition
//ELSE
// Base case: array is 1 element or smaller in size – already sorted
ENDIF
ENDFUNCTION
FUNCTION doPartitioning IMPORT array, leftIdx, rightIdx, pivotIdx EXPORT newPivotIdx
pivotVal ??array[pivotIdx]
array[pivotIdx] ??array[rightIdx] ?Swap the pivotVal with the right-most element
array[rightIdx] ??pivotVal
// Find all values that are smaller than the pivot
// and transfer them to the left-hand-side of the array
currIdx ??leftIdx
FOR (ii ??leftIdx TO rightIdx-1)
IF (array[ii] = pivotVal, so it can be put to the end)
ENDFUNCTION
Shell sort in ascending order, with initial increment =…

ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

HOME TO CERTIFIED WRITERS

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing

Have a similar question?

PLAGIRAISM FREE PAPERS

All papers we provide are well-researched, properly formatted and cited.

TOP QUALITY

All papers we provide are well-researched, properly formatted and cited.

HIGHLY SECURED

All papers we provide are well-researched, properly formatted and cited.

ScholarMatic: Get Started

Assignment Writing Service

Feel safe and secure when placing an order on our portal!
Fruitful cooperation begins with solid guarantees, and we are professional enough to promise perfect results. Let’s get it started!