Question: using System; using System.Collections.Generic; using System.Diagnostics; namespace SimpleSort { class Sort { static void Main(string[] args) { Console.Write( How many random numbers to you want
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SimpleSort
{
class Sort
{
static void Main(string[] args)
{
Console.Write(" How many random numbers to you want to sort = ");
string UserInput = Console.ReadLine();
int size = Convert.ToInt32(UserInput);
Random rand = new Random();
int[] arr = new int[size];
Console.WriteLine(" Unsorted------------");
//Generate an unsorted array
for (int i = 0; i
{
arr[i] = rand.Next(0, 100);
Console.WriteLine(" " + arr[i]);
}
Console.WriteLine(" Built-In Sort------------");
//The built-in "arr.Sort" sorts "in-place",
//i.e. it destroys the original unsorted arr.
//We need to make a temporary copy of the original.
int[] temp = new int[size];
Array.Copy(arr, temp, size);
Stopwatch s = new Stopwatch(); // start the stopwatch
s.Start();
Array.Sort(temp);
s.Stop(); //stop the Stopwatch and print the elapsed time
Console.WriteLine(" It took {0} to sort {1} numbers ", s.Elapsed, size);
for (int i = 0; i
Console.WriteLine(" Selection Sort------------");
SelectSort(arr);
for (int i = 0; i
Console.ReadKey();
}
static void SelectSort(int[] arr)
{
int min;
int min_index;
int temp;
int size = arr.Length;
Stopwatch s = new Stopwatch(); // start the stopwatch
s.Start();
for (int i = 0; i
{
min = arr[i];
min_index = i;
for (int j = i + 1; j
{
if (arr[j]
}
// the smallest element smaller than the current head of the list (if there is one)
// is swapped with the current head of list.
if (min_index != i)
{
temp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = temp;
}
}
s.Stop(); //stop the Stopwatch and print the elapsed time
Console.WriteLine(" It took {0} to sort {1} numbers ", s.Elapsed, size);
}
}
}

1. Assignment 1 (50 Points) Use the selection sort program discussed in class (attached) and run it with inputs of length, 25, 50, 75, 100, 150, 200, 250, 300, 350, 400. Record the execution times for our selection sort and the built-in sort. Enter the recorded execution times into Excel and graph. On the same graph also graph n^2, and n*log(n) (using the same values for n (25, 50, 75, 100, 150, 200, 250, 300, 350, 400). 1. Assignment 1 (50 Points) Use the selection sort program discussed in class (attached) and run it with inputs of length, 25, 50, 75, 100, 150, 200, 250, 300, 350, 400. Record the execution times for our selection sort and the built-in sort. Enter the recorded execution times into Excel and graph. On the same graph also graph n^2, and n*log(n) (using the same values for n (25, 50, 75, 100, 150, 200, 250, 300, 350, 400)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
