optional exercise 5

Prerequisites: Students should have mastered the following prerequisite skills.

;Sorting - Knowledge of selection sort and quicksort

;Complexity - Knowledge of basic asymptotic analysis and Big-Oh notation Goals: This assignment is designed to reinforce the student's understanding of basic and fast sorting algorithms and complexity.

Outcomes: Students successfully completing this assignment would master the following outcomes.

;Understand selection sort and quicksort

;Understand the difference between stable and non-stable sorting algorithms Background

A stable sort is a sort algorithm that performs the same amount of work regardless of the data being sorted. The amount of work a non-stable sort performs, on the other hand, can

vary significantly depending on the arrangement of data. This translates to stable sorts having identical best case, worst case, and average case complexity. The worst case complexity of a non-stable sort can be an entirely different runtime class than its best or average case.

Description

The program to be completed for this assessment demonstrates the runtime differences between a stable and non-stable sort. The stable sort examined in this assessment is selection sort and the non-stable algorithm examined in this assessment is quicksort. Each algorithm is encapsulated in a corresponding class. Method init of these classes

populates an array. This function populates the array with data that triggers either the average or worst case of the algorithm. For the stable sort algorithm, selection sort, the average and worst case are identical. The quicksort algorithm, on the other hand, has distinct worst and average cases. A supplied main routine repeatedly initializes and sorts these arrays to demonstrate the differences between the stable and non-stable sort algorithms. The correct implementation of method init requires the generation of random numbers.

Use the rand library function to generate a random integer.

Note to Viusal C++ users: The default stack size in Visual C++ is 1 MB. To execute your solution, you should increase the stack size in your system.

To increase the stack to 10 Mb:

1.On menu Project, select the project Properties.

2.Expand Configuration Properties.

3.Expand Linker.

4.Select System.

5.On Stack Reserve Size, write 10485760.

6.On Stack Commit Size, write 10485760.

Files

Following is a list of files needed to complete this assessment.

;handout-files.zip contains all of the following necessary files:

omain.cpp - This file contains the main routine.

osort.h - This declares a sort class.

osort.cpp - This defines class sort.

oquicksort.h - This declares a quicksort class.

oquicksort.cpp - This defines class quicksort.

oselectionsort.h - This declares a selection sort class.

oselectionsort.cpp - This defines class selectionsort.

Tasks

To complete this assessment, you need to complete the init methods of class quicksort

and class selectionsort.

To begin, verify the files needed for this assessment.

1.Extract the archive to retrieve the files needed to complete this assessment. Following is an ordered list of steps that serves as a guide to completing this assessment.

Work and test incrementally. Save often.

1.Begin by making sure you understand what makes selection sort a stable sort