Question: In C#: Obtain individual running times for three code segments. The different functions (that you write) must be (a) O(n), (b) O(n 2 ), and
In C#:
Obtain individual running times for three code segments. The different functions (that you write) must be
(a) O(n), (b) O(n2), and (c) O(n) + O(n2).
You can use different values of n for each code segment (e.g. for n, you may need to use some pretty large values for n; for n2, start with smaller n values). It is best to run the O(n) one separately using some larger values for n.
To get better results for each value of n, run a function multiple times, throw out any outliers, and average the remaining running times. To get different values of n, change n's values and run the program again.
Details: You must have "using System.Diagnostics;" to use the Stopwatch class. Similar to a stop watch: you start the stopwatch object, run your code, then stop the stopwatch object and look at the elapsed time. Switch from Debug to Release for the Configuration on the toolbar below the TEAM menu item.
Example:
Stopwatch timer = new Stopwatch(); timer.Start(); // Start the timer // code to time // Use loop(s) with something slow inside like double.TryParse("3.14159",out doubleVariable). timer.Stop(); // Stop the timer decimal micro = (decimal)timer.Elapsed.Ticks / 10M; Console.Write("{0,5:F1},", micro);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
