Question
I only need you to do the insertion sort algorithm instead of a binary search for my C Sharp code and bottom output: my C
I only need you to do the insertion sort algorithm instead of a binary search for my C Sharp code and bottom output:
my C sharp code is must include:
- use the insertion sort, use an array of 100 random integers, run the test 10 times, calculate the average "loop count", determine average execution time in milliseconds. I have all, but I just only need you to help me to use "INSERTION SORT" instead of my "Binary Search".
using System; using System.Diagnostics;
class Program { //I START TO DO BINARY SEARCH//RETURN THE INDEX IF FOUND & -1 IF NOT FOUND//UPDATE REFERENCE PARAMETER LEVELS & THE NUMBER OF LEVELS IT TOOK static int binarySearch(int[] array, int target, ref int levels) { //THE LEVELS SHOULD RESETTING levels = 0; //THE VARIABLES SHOULD DECLARING AS LOW, MIDDLE, HIGH int low = 0, high = array.Length - 1, mid; //LOOPING & LOOPING UNTIL MY LOW REACH NEAR TO MY HIGH while (low
//SORTING, MR. GRAY SAID: "NOT DOING THINGS WITHOUT SORTING." Array.Sort(array);
//DISPLAYING SORTED ARRAY Console.WriteLine("Sorted by Mehran:"); for (int i = 0; i maxLevel) { maxLevel = level; } //LEVELS ADDING TO SUM LEVELS sumLevels += level; //DISPLAYING CURRENT SEARCH IN THE MIDDLE OF MY OUTPUT Console.WriteLine("target={0}, index={1}, level={2}", target, index, level); } //AVERAGE TIME DETERMINATION, FINDING MY AVERAGE TIME TOOK FOR MY BINARY SEARCH avgTimes = (double)sumTimes / 10; //I FOUND THIS SPECIFIC PART TO CONVERT AVERAGE TIME TO MILISECOND AS REQUIREMENT avgTimes = avgTimes / TimeSpan.TicksPerMillisecond; //FINDING AVERAGE LEVEL avgLevels = (double)sumLevels / 10; //DIPLAYING, DIPLAYING, DISPLAYING//FINALLY, AFTER FOUR NON-STOP WORKING HARD I'VE GOT IT Console.WriteLine("Mehran Binary search: {0} ms, average level={1}, max level={2}", avgTimes, avgLevels, maxLevel);
//REMOVE IF YOU ARE DONE! PRESS ANY KEY TO QUITE Console.ReadKey(); } }
CA C:\Program Files\dotnet\dotnet.exe - a X 22 22 22 24 25 26 27 31 31 32 32 33 34 36 36 37 38 38 40 41 41 41, 42 43 43 43 44 44 46 48 48 51 52 54 57 58 58 59 60 63 63 64 65 67 68 68 69 70 70 70 71 73 73 75 76 77 79 80 83 85 86 87 89 91 93 93 94 95 95 95 96 96 96 target=52, index=59, level=6 target=87, index=88, level=6 target=38, index=43, level=6 target=93. index=91, level=6 target=73. index=78, level=6 target=52, index=59, level=6 target=54. index=60, level=7 target=91. index=90, level=5 target=63, index=67, level=4 target=41, index=47, level=6 Mehran Binary search: 0.03241 ms, average level=5.8, max level=7 CA C:\Program Files\dotnet\dotnet.exe - a X 22 22 22 24 25 26 27 31 31 32 32 33 34 36 36 37 38 38 40 41 41 41, 42 43 43 43 44 44 46 48 48 51 52 54 57 58 58 59 60 63 63 64 65 67 68 68 69 70 70 70 71 73 73 75 76 77 79 80 83 85 86 87 89 91 93 93 94 95 95 95 96 96 96 target=52, index=59, level=6 target=87, index=88, level=6 target=38, index=43, level=6 target=93. index=91, level=6 target=73. index=78, level=6 target=52, index=59, level=6 target=54. index=60, level=7 target=91. index=90, level=5 target=63, index=67, level=4 target=41, index=47, level=6 Mehran Binary search: 0.03241 ms, average level=5.8, max level=7
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started