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

  Construct vector and linked lists data structures

You will prepare sorted versions of the Linked Lists and Vector data structures developed in class

  Your city''s parking violation

Your city's Parking Violation Bureau wants you to write a program to compute fines for parking violations.

  Write a program to read only one integer number

Write a program to read ONLY one integer number (your input must be one 3 digit number from 100 to 999), and to think of a number as being ABC (where A, B, and C are the 3 digits of a number)

  Machine that i would like to know

Let's say I have a machine that I would like to know, on average, how much it runs throughout a given day through a percentage value. Every 30 seconds, I will have a device to record the current temperature of the machine. If the machine increases..

  Develop a basic temperature class

You have to develop a basic temperature class

  Create a base employee class

Create a base Employee class and a derived StudentEmployee class

  Program to input the length of the side from the keyboard

write a program to input the length of the side from the keyboard ,use the class to obtain the areas of all shapes and display the results on the screen

  Need c++ solution to cover the final stage of euro 2012

From Group Fase to elimination fases, it´s not the user who defines teams, because that must be made automatically according to classification in group fase - considering regulations.

  The function should return a value

The function should return a value of 1 when it is given a valid score to process and 0 when the received value is out side of the 0-10 range. In this case it should print a waring message on the screen

  Prompts the user to enter the mass of a person

Write a program that prompts the user to enter the mass of a person in kilograms and outputs the equivalent weight in pounds. Output both the mass and the weight rounded to two decimal places

  50 element array of integers with random numbers

write a java code to instantiate and initialize a 50 element array of integers with random numbers in the range of 45 through 256 inclusive.

  Native method with deadlock detection and recovery

The naïve method with deadlock avoidance and the naïve method with deadlock detection and recovery - what will you measure and compare in order to determine the winner or which is better

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