Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3808831 • Letter: T

Question

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

1. Write a computer program that prompts the user for a number, creates an array for that number of random integers, and then uses 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.

2. Repeat 1 but use selection sort this time.

1 and 2 are primarily intended to make sure that your algorithms work.

Once you are convinced your programs work, do the following

3. Write a computer program that prompts the user for two numbers, n for the number of items in the array to sort, and num_i for a number of arrays of this size to sort. Then do the following:

Initiate a variable running_time to 0

Create a for loop that iterates num_i times.

In the body of the loop,

Create an array of n random integers

Get the time and set this to start-time. You will have to figure out what the appropriate command is in the programming language you are using to find them time

Use bubble sort to sort the array

Get the time and set this to end-time

Subtract end-time from start-time and add the result to running_time

Once the program has run, note

The number of items sorted

The number of iterations

The average running time for each size array

Repeat the process nine times, using 50, 250 and 500 as the size of the array, and 100, 1000 and 10,000 as the number of arrays of each size to sort.

4. Repeat 3 using selection sort.

I ALREADY HAVE THE CODES, PLEASE JUST HELP ME WITH NUMBER 6 BELOW

6. Please explain 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.

Explanation / Answer

Complexity analysis:

The number of operations involved while running a program are measured using complexity analysis. There are various ways to measure time complexity of an algorithm.

Big-O notation:

Big O notation bounds a function from above only, that is a function f(n) is said to be O(g(n)) if for n>n0 (n0 is a constant) there exists a constant c such that 0 <= f(n) <= c*g(n).

Notation:

notation bounds a function from above and below as well. f(n) is a non-negative function, for n > n0, If f(n) is (g(n)), then the value f(n) is always between c1*g(n) and c2*g(n), where n0, c1 c2 are constants.

In the given question, the time complexity of both the sorting algorithms is O(n^2) where n is the size of array. And when we promt user 2 values, n for the number of items in the array to sort, and num_i for a number of arrays of this size to sort, Basically we call sort algorithm num_i times.

So the time complexity of the overall program will be O(num_i*n^2). Hence the time required for whole program to run will be proportional to num_i*n^2. Whereas time required to sort each array of size n inside the for loop will be proportional o n^2.