How many times would you like to shuffle the sorted list

Assignment Help C/C++ Programming
Reference no: EM13336442

Sorting & Searching

The purpose of sorting is to put a sequence of data records in ascending or descending order based on a sorting key. For example, to sort student records based on last name, or sort football player records based on batting average. The problem of sorting data has been around a long, long time. The purpose of this assignment is to evaluate the performance of two well known sorting algorithms: bubble sort and selection sort. We will do this by calculating the CPU times to sort different types of input data (unsorted, semi-sorted, and sorted). There are two ways to generate unsorted data for sorting experiments. The first way is to use a random number generator and create N values within a range [L..H]. This is like rolling dice over and over again. The second method starts with sorted data and randomly shuffles data around to create unsorted data. This is essentially what we do when we shuffle a deck of cards. Once the sorted data re produced, a specified value (the input "key") within the sorted data can be found by employing different searching techniques.

Program Specification

You are required to design, implement and test a program in C++ to generate N values within a certain range [L..H]. The well known sorting algorithms, bubble sort and selection sort are then applied to the unsorted set of data. The performances of these methods are measured by calculation the CPU running time of each. Given an input key, a specified data can then be searched within the sorted data. The developed program should perform the following operations :

1. Random Generation of Unsorted Values

Using a number generator, the program is to create N values within a range [L..H]. You will need to define a function for generating random numbers. The function will then be called within the main program.

Example input/output might be: ( the output is in italic)

Enter the number of values to be generated: 6

Enter the range : 50

The unsorted generated sequence is :

34 12 6 47 22 19

2. Sorting

You will need to add two functions to your program to sort the list generated in part (a), using bubble sort and selection sort algorithms. Since the output of both algorithms will be the same (sorted list), you will need to only display the result for one of them.

Example input/output might be:

The sorted list is now:
6 12 19 22 34 47

3. Measuring the running-time

The performance of two sorting algorithms should be compared by calculating the CPU time of each algorithm for the same set of data. Calculate the run times for N=1000. If the times are too small to measure, increase N as needed until you can get a CPU time greater than a few seconds. Stop your program if it uses more than a minute of CPU time and decrease N accordingly.

Example input/output might be:

Enter the number of values to be generated: 5000

Enter the range: 100

The unsorted generated sequence is:

34 88 61 47 22 19 77 12 93.............


The sorted list is now:

12 19 22 34 47 61 77 88 93.....

The bubble sort-algorithm sorted the 5000 values in 2.34 second
The selection sort-algorithm sorted the 5000 values in 2.05 second


4. Shuffle the Sorted List

You will need to add a function named, Shuffle to your program, to allow for shuffling the sorted list in part (b). By shuffling the sorted list, we create a semi-sorted list. Shuffling data values inside data array is done by swapping random pairs of values. For example, shuffling three times, will swap 3 random pairs of values. Try a few different values of the "shuffles" parameter to create data that looks semi-sorted (some sequences of values are in the correct order, but others are out of order. Try a few different values of the "shuffles" parameter to choose a value that creates data that looks semi-sorted (some sequences of values are in the correct order, but others are out of order).

Example input/output might be:

How many times would you like to shuffle the sorted list?

The semi-sorted list is now:

6 12 19 22 34 47

6 19 12 22 47 34


5. Searching for a Specific value

You will need to add a function named, Search to your program to allow searching for a specific vale in the sorted list. You are recommended to use the Binary Search algorithm because of its efficiency. Once the function is called within the main program, specifying the key value, the function should return the first occurrence of the value in the list. Your program should also calculate the time for finding the key value.

Example input/output might be:

The sorted list is now:
6 12 19 22 34 47

Enter the key value to be searched: 22

The first occurrence of 22 is at position 4
It took 0.0 4 second s to find the value.

Assignment's Tasks


Task 1: Algorithm Design

You are required to produce a top-level design for your program using pseudocode or flowcharts. In addition to your design, a Function Table should also be provided.


Task 2: Program Development

You are required to implement your designs in C++ Programming Language. Your program should be properly laid out and should be modular, making sure that software engineering aspects of modularity and reusability are fully considered.


Task 3: Program Testing & Documentation

• Devise a test plan carefully, making sure that the purpose of the particular test is clearly stated, the data for each test is specified (that is, any inputs expected from the user or the programmer), and a description of the expected result from the test are also provided.

• Use the test plan to test your program and document your findings. You should provide a hard copy of the actual output from your program, in the same order as your test plan and cross-referenced to it.

• You may like to test some functions separately. Any aspects of your program which you do not test will be assumed not to work.

• Your program must handle incorrect input data. Your testing should then include incorrect input data.


• You are required to provide an annotated code listing in addition to your proof of testing.


Task 4: Program Evaluation

You should evaluate your program, carefully identifying its strengths, weaknesses, and possible areas of improvement. You should also comment on the extent to which your solution correctly satisfies the specification.

Reference no: EM13336442

Questions Cloud

What issues prompted the revision fo the federal sentencing : What issues prompted the revision fo the federal sentencing guidelines for organizations in 2004?
What is the payback period without discounting cash flows : Consider the following four-year project. The initial after-tax outlay is $550,000. The future after-tax cash inflows for years 1, 2, 3 and 4 are: $175,000, $250,000, $280,000 and $200,000, respectively.
Depict the structures of the secondary alcohols : Draw the structure(s) of the secondary alcohols with the chemical formula C6H14O that have a 6-carbon chain.Although stereochemistry may be implied in the question, DO NOT consider stereochemistry in your drawing.
Financial reporting for publicly traded companies : How has the Sarbanes-Oxley Act of 2002 affected financial reporting for publicly traded companies? Do you think that the Sarbanes-Oxley Act is effective in promoting ethical behavior for financial professionals? Why or why not?
How many times would you like to shuffle the sorted list : You are required to implement your designs in C++ Programming Language. Your program should be properly laid out and should be modular, making sure that software engineering aspects of modularity and reusability are fully considered.
Calculate the force that the road exerts on the vehicle : A banked curve has been designed so that it is safest for a vehicle going 70mph. A 5512 lb vehicle travels with a speed of 60 mph on the curve. Calculate the force that the road exerts on the vehicle
Depict structural formula for allyl alcohol : Draw structural formula for allyl alcohol. Use stereo bonds ONLY if in your example you are asked to draw a particular stereochemistry.
What is the expected non-operating terminal cash flow : The total cost for the new capital totals $718,000 with installation costs of $5,000. Inventories will increase by 6,500, accounts recieveable will increase by 4,000 and accounts payable will increase by 3500.
Who make buying decisions for organizations : Who make buying decisions for organizations

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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