Question

The purpose of the project is to perform a timing experiment. You are required to complete...

The purpose of the project is to perform a timing experiment. You are required to complete the following activities: Write a computer program that prompts the user for a number, creates an array for that number of random integers, and then usees the bubble sort to order the array. The program should print out the array prior to the call to the sorting algorithm and afterwards. You can write the program in either Java, C++, C#, or whatever language you are most comfortable in. Do Not use an API from the language library. Write the program to perform the sort. Repeat 1 but use selection sort this time. Again, write out the program for the selection sort. DO not use the language library. 1 and 2 are primarily intended to make sure that your algorithms work. Once you are convinced your programs work, do the following Write a computer program that prompts the user for one number, n for the number of items in the array to sort, and create and sort 1000 different arrays of this size timing the run to get an average time to sort an array of this size. Then do the following: Initiate a variable running_time to 0 Create a for loop that iterates 1000 times. In the body of the loop, Create an array of n random integers Get the time and set this to start-time (notice the sort is started after each array is built. You want to time the srt process only). You will have to figure out what the appropriate command is in the programming language you are using to find the time (Important: Do not start the timer until after the array is created). Use bubble sort to sort the array Get the time and set this to end-time Subtract start-time from end-time and add the result to total_time Once the program has run, note The number of items sorted The average running time for each array (total_time/1000) Repeat the process using 500, 2500 and 5000 as the size of the array. Repeat 3 using selection sort. You now have 6 data points ( the averages from the three array sizes for the two sort algorithms) Create a spreadsheet showing the results of 3 and 4 and create a graph to graphically represent the information. Show both sort algorithms on the same graph for comparison. Write a one page document explaining the results, bearing in mind that both algorithms have a complexity of O(n^2) and what you know about complexity analysis. Use your knowledge of complexity analysis to explain your results.

Please, I need main focus on the one page paper explaining the results!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

first of all we need to take the value of n ie number of element array element we have to enter by using

in c language

print("enter value of n");

scanf("%d",&n);

it store the value of at variable n;

now time to n number of array element using for loop upto n number of elements.

for(int i=0;i<n;i++)

{

scanf("%d",&a[i]);

}

to read array element at address &a[i] upto n number of elements.

suppose value of n=5

then using for loop read value of array element usign for loop

56 78 2 45 1

now to arrange array element in increseing order using bubble sort we have to compare each element to the next element if a[i]>a[i+1]

swap to next

like 56 and 78

56>78 not so increment count and then compare a[1] and a[2]

ie 78 and 2 78>2 so swap the list and at the end of first pass on of the greatest element is sorted at the bottom of list.

56 2 45 1 78

and in second pass second gretest element i.e 56 is sorted at botom of list

2 45 1 56 78

and so on

1 2 45 56 78 at the and of pass n-1 list get sorted.

use nested for lop for comparision

for (i=0;i<n-1;i++)/*for n-1 passes*/

{

for(j=0;j<n-1;j++)

ifa[j]>a[j+1]

temp=a[j];

a[j]=a[j+1];

a[j=1]=temp;/*swaping logic*/

}

and after the end of this storted list is generated and with the help of for loop display the output

for(j=0;j<n;j++)

printf(" ",a[i]);

in this way bubble sort will be working and at the end of each pass one of the greatest element is sorted at the bottom of list and hence called as bubble sort.

and total n-1 passes are required to sort the list

where n indicate total number of element in list

in our example value of n=5

so n-1 ie 5-1=4

passes are required to sort the list .

and use for loop to read array element

and nested for loop to compare and swap element to generate sorted list

and for loop to display sorted array elements.

Add a comment
Know the answer?
Add Answer to:
The purpose of the project is to perform a timing experiment. You are required to complete...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE DO BOTH #5 AND #6. The purpose of the project is to perform a timing...

    PLEASE DO BOTH #5 AND #6. The purpose of the project is to perform a timing experiment. You are required to complete the following activities: Write a computer program that prompts the user for a number, creates an array for that number of random integers, and then usees the bubble sort to order the array. The program should print out the array prior to the call to the sorting algorithm and afterwards. You can write the program in either Java,...

  • Write a computer program that prompts the user for one number, n for the number of...

    Write a computer program that prompts the user for one number, n for the number of items in the array to sort, and create and sort 1000 different arrays of this size timing the run to get an average time to sort an array of this size. Then do the following: Initiate a variable running_time to 0 Create a for loop that iterates 1000 times. In the body of the loop, Create an array of n random integers (Make sure...

  • Be sure to include the number of total swaps in each sort. Create a total_Time variable...

    Be sure to include the number of total swaps in each sort. Create a total_Time variable is the total time it takes all 1000 iterations to run. DO NOT INCLUE THE TIME IT TAKES TO GENERATE A UNIQUE RANDOM ARRAY EACH LOOP. In java, Write a computer program that prompts the user for one number, n for the number of items in the array to sort and create and sort 1000 different arrays of this size,  timing the run to get...

  • PLEASE ANSWER #5AND #6, THE ANSWER FOR #3 AND #4 ARE ALREADY PROVIDED!!! 3 .Using Java,...

    PLEASE ANSWER #5AND #6, THE ANSWER FOR #3 AND #4 ARE ALREADY PROVIDED!!! 3 .Using Java, Write a computer program that prompts the user for one number, n for the number of items in the array to sort, and create and sort 1000 arrays of this size timing the run to get an average time to sort an array of this size. Then do the following: Initiate a variable running_time to 0 Create a for loop that iterates 1000 times....

  • Write a program that compares the execution speed of two different sorting algorithms: bubble sort and...

    Write a program that compares the execution speed of two different sorting algorithms: bubble sort and selection sort. It should do this via functions you must write with the following prototypes: void setRandomValues(int[], int[], int length); This function sets two integer arrays with identical random values. The first two arguments are two integer arrays of the same length, and the third argument is the length of those arrays. The function then sets each element in the first and second argument...

  • Comparison of Sorting Algorithms You are required to implement all the sorting algorithms (Bubble, Selection, Insertion...

    Comparison of Sorting Algorithms You are required to implement all the sorting algorithms (Bubble, Selection, Insertion, Quick, Merge). Take help from lecture slides and welb . You will then create arrays of different sizes as instructed below, test each algorithm on each array and record the execution times of each individual algorithm on each array. . You will report these execution times in a table and then write a report explaining the execution times of the sorting algorithms according to...

  • Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays....

    Write a JAVA Program: Compare the performance of bubble sort and selection sort over several arrays. - Write two methods that sort arrays of doubles. One method should use selection sort, and the other should use bubble sort. - In each of the sort methods, add code that counts the total number of comparisons and total number of swaps performed while sorting the entire array (be careful; don't count each pass through the array separately) - Each time an array...

  • Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of...

    Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of data and arranging items in an ascending/descending order. you will also explore storing lists/arrays using different sorting algorithms including, the selection sort, bubble sort, and insertion sort algorithm. Comparison between the three algorithms are made based on the number of comparisons and item assignments (basic operations) each algorithms executes. Background: Ordering the elements of a list is a problem that occurs in many computer...

  • In this lab we are going to complete a profile of two sorting algorithms by running...

    In this lab we are going to complete a profile of two sorting algorithms by running some tests to collect empirical data. 1. First we need to be able to generate some random integers. You can do this by including the following library : #include Now first run the following to generate a seed : srand (time(NULL)) You can then generate a random number using the function rand() 2. We will use two sort algorithms - Selection Sort and Bubble...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT