Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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);

}

}

}

image text in transcribed

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). 2. Problem 1 (50 points): Ask the user to enter a string (e.g. Welcome to Saint Martin's U!). Your program should count and display the total number of vowels (A, E, I, 0, U) - count both uppercase and lowercase vowels - in that given input. In the example above, the output should 9. [Hint: Convert the string to all upper (or all lower) case to safe having to check 'A' or 'a' for each vowel respectively.] 3. Problem 2 (50 points): Ask the user to enter a positive integer b. Validate the input (to make sure it is positive). Then output whether or not the number b is divisible by 3. (Hint: Modulus operator]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions