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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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