Provide a description of the algorithm in pseudocode

Assignment Help Basic Computer Science
Reference no: EM13309283

Part-1

Sorting Algorithms & Analysis
Objectives from the Unit Outline
Apply complexity theory to algorithms;
Discuss the relative merits of sort techniques using various abstract data types;
------------------------------------------------- ------------------------------------------------- ------------------------------------------------- ------------------------------------------------- ------------------------------------------------- ------------------------------------------------- -------------------------------------------------
The Tasks:

Question 1:

You are required to create a detailed analysis for each of the following array-based sorting algorithms:

(a) bubble sort in ascending order;
(b) quick_sort in ascending order, with partition choosing pivot in the middle of the sub-array;
(c) shell_sort in ascending order, with initial increment = n/2, then increment /=2;
(d) heap_sort in ascending order;

To analyse each of the abovementioned algorithms, please

1)provide a description of the algorithm in pseudocode;
2)conduct time complexity analysis of the algorithm (and also mention best case and worst caseanalysis if applicable);
3)conduct space complexity analysis of the algorithm;
4)Hand test your algorithm using your allocated 10-element long list of alphabetic charactersas an illustrative example (see the Data Set below, and treat them as an array),
ocount the number of comparisons;

ore-arrange your data set so as to achieve the best-case sorting of the algorithm;
ore-arrange your data set so as to achieve the worst-case sorting of the algorithm.

Question 2:

You are required to provide a detailed analysis of the following sorting algorithm applied to sorting linked list-based data structures.
merge_sort in ascending order

Similar to the case of Question 1, analyse the algorithms by

1)providing a description of the algorithm in pseudocode;
2)conducting time complexity analysis of the algorithm (and also mention best and worst caseanalysis if applicable);
3)conducting space complexity analysis of the algorithm;
4)hand testing your algorithm using your allocated 10-element long list of alphabeticcharacters as an illustrative example (see the Data Set below, and treat them as sequentialelements of an linked list),
ocount the number of comparisons;

ore-arrange your data set so as to achieve the best-case sorting of the algorithm;
ore-arrange your data set so as to achieve the worst-case sorting of the algorithm.

Data set

Allocated a 10-element array of alphabetic characters, which will be used for his/herillustrative hand testing of the algorithms.
Find his/her Dataset (or, Individual list to be sorted), of string format, ABCDEFGHIJ, which represents an array (or linked-list of) { A, B, C, D, E, F, G, H, I, J} (marked red).

Notes and awards:

The main objective of this assignment part is of algorithm analysis. As such, it doesn't require Java implementation of individual algorithms. However you are encouraged to implement them in Java if you have time to do so. If you attempt to do so, please save your executable java code/s separately, and submit them with your main document.
Your string will be KIMZUTONLV

Part-2

(a)    Bubble sort in ascending order.

1.      Pseudo code:

FUNCTION BubbleSortIMPORT 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

 

(b)   Quick sort in ascending order, with partition choosing pivot in the middle of the sub-array.

2.      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) THEN¬Find the next value that should go on the left

temp¬ array[ii]¬Put this value to the left-hand-side

array[ii] ¬ array[currIdx]

array[currIdx] ¬ temp

currIdx¬ currIdx + 1

ENDIF

ENDFOR

newPivotIdx¬ currIdx

array[rightIdx] ¬ array[newPivotIdx]¬Put the pivot into its rightful place (the value at

array[newPivotIdx] ¬ pivotVal[newPivotIdx] is >= pivotVal, so it can be put to the end)

ENDFUNCTION

 

(c)    Shell sort in ascending order, with initial increment = n/2, then increment /=2.

3.      Pseudo code:

 

 

FUNCTIONShellSortIMPORTsize

   for (inc¬size/2 inc>0inc /= 2)

 

      for (i¬inci< sizei++)

 

         j¬i - inc

         while (j >= 0)

 

            if (a[j] > a[j+inc])

 

               swap a[j] and a[j+inc]

               j -¬inc

            else

               j¬-1

ENDFUNCTION

 

 

 

 

Reference no: EM13309283

Questions Cloud

Compute the next-to-the-longest wavelength in series of line : A certain species of ionized atoms produces an emission line spectrum according to the Bohr model, Find the next-to-the-longest wavelength in the series of lines
How realistic is the sales maximization model : How realistic is the sales maximization model from experience with business objectives as pursued by Zimbabwean firms
Define disodium hydrogen phosphate : What would happen to the A450 value for a smaple which include : 1mL of 0.0025M Fe(NO3)3 + 1mL of 0.0025M KSCN + 5.0mL of 0.1M HNO3 , if you accidentally added 5 drops of disodium hydrogen phosphate
Find the frequency of the reflected sound wave heard : An ambulance siren is the source of sound emitted with a frequency of 1600 Hz. What is the frequency of the reflected sound wave heard at the ambulance
Provide a description of the algorithm in pseudocode : You are required to create a detailed analysis for each of the following array-based sorting algorithms.
What is the magnitude of the other charge : A 5 mC charge is located 1.8 m away from another charge. If the force between the charges is 5.0 N, what is the magnitude of the other charge
Compute the kinetic energy of the mass : A mass vibrates at the end of a spring with simple harmonic motion. The spring constant is 30 N/m. What is the kinetic energy of the mass when it is at half its amplitude
Determine what is the probability the lot is full : If vehicle arrivals at the lot follow a poisson process, with arrival rate lambda = 0.2 vehicles/hour, what is the probability the lot is full at 9:15 AM. Assume that no one leaves during this period.
Find the cross-sectional area of each wire : The rear window of a car consists of thirteen thin wires (resistivity = 88.0 * 10^-8 ohms) embedded in the glass. Find the cross-sectional area of each wire

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Write a c++ program that read an integer

Write a C++ program that read an integer.The code will check if the number is divisible by 3, it will print the number is divisible by 3.

  How do you write a program in visual basic

My problem is the program should pretty much erase the pervious series data points for the control limits for both charts and update the new value with the recalculated values, and I am not sure how to do this. Thank you!

  Write a program that displays employees

Suppose the weekly hours for all employees are stored in a two-dimensional array. Each row records an employee's seven-day work hours with seven columns.

  Why information technology is a business pressure

Explain in detail why Information Technology (IT) is a business pressure and also an enabler of response activities.

  What are different types of memory

What are some of the newer technology innovations you have seen in regards to I/O and Memory? What are the different types of Memory and how much is recommended?

  Results of password cracker designed for operating system

Download a password cracker designed for your operating system. Run the cracker on your system. Explain the results from the cracker.

  Write a program that reads the data in the file and displays

Write a program that reads the data in the file and displays the car number, miles driven, gallons used and the miles per gallon for each car.

  Find final contents of cache using direct-mapped cache

Suppose direct-mapped cache with 16 one-word blocks that is initially empty, label each reference in list as hit or miss and find final contents of the cache.

  How a large output impedence effect the behavior op circuit

How would a large OUTPUT impedence effect the behavior of an op amp circuit? please talk about how the large output impedence would effect the circuit.

  Validate a field for minimum length

Write a JavaScript program that performs the following actions (in sequence, step-by-step):

  Discuss strategies to dilute manager-s anger

Discuss strategies you will use to dilute this manager's anger. Discuss how you will get them both to support your recommendations.

  Determine the optimal plan

DSS Inc. is an electronics company with production facilities located in Atlanta, Boston, and Chicago. Components produced at these facilities may be shipped to the firm's regional warehouses that are located in Edison and Fargo.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd