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: 3851165 • Letter: T

Question

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 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.

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

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 iterations. 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 iterations.

Repeat 3 using selection sort.

Create a spreadsheet showing the results of 3 and 4 and create a graph to graphically represent the information

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.

Can anyone just help me with the report explaining how effective each of the sorting method is?

Explanation / Answer

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:

Introduction:

A lot of programmers that make some of the coolest and most useful
software today, such as many of the stuff we see on the Internet or use
daily, don't have a theoretical computer science background.
They're still pretty awesome and creative
programmers and we thank them for what they build.

However, theoretical computer science has its uses and
applications and can turn out to be quite practical. In this article,
targeted at programmers who know their art but who don't have any
theoretical computer science background, I will present one of the most
pragmatic tools of computer science: Big O notation and algorithm
complexity analysis. As someone who has worked both in a computer
science academic setting and in building production-level software
in the industry, this is the tool I have found to be one of the truly
useful ones in practice, so I hope after reading this article you can
apply it in your own code to make it better. After reading this post,
you should be able to understand all the common terms computer scientists
use such as "big O",
"asymptotic behavior" and "worst-case analysis".

BUBBLESORT:

import java.util.Scanner;

class BubbleSort {
public static void main(String []args) {
int n, c, d, swap;
Scanner in = new Scanner(System.in);

System.out.println("Input number of integers to sort");
n = in.nextInt();

int array[] = new int[n];

System.out.println("Enter " + n + " integers");

for (c = 0; c < n; c++)
array[c] = in.nextInt();

for (c = 0; c < ( n - 1 ); c++) {
for (d = 0; d < n - c - 1; d++) {
if (array[d] > array[d+1]) /* For descending order use < */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}

System.out.println("Sorted list of numbers");

for (c = 0; c < n; c++)
System.out.println(array[c]);
}
}

========================OR================

public class BubbleSortExample {
static void bubbleSort(int[] arr) {
int n = arr.length;
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(arr[j-1] > arr[j]){
//swap elements
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
  
}
}
  
}
public static void main(String[] args) {
int arr[] ={3,60,35,2,45,320,5};

System.out.println("Array Before Bubble Sort");
for(int i=0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
  
bubbleSort(arr);//sorting array elements using bubble sort

System.out.println("Array After Bubble Sort");
for(int i=0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}

}
}