For each of the code segments below determine an equation fo

For each of the code segments below, determine an equation for the worst-case computing time T(n) (expressed as a function of n, i.e. 2n + 4) and the order of magnitude (expressed using big O notation, i.e. O(n)). a.//Calculate mean n = 0; sum = 0; cin >> x; while (x != -999) {n++; sum + = x; cin >> x;} mean = sum/n;

Solution

a) The code stops when the number -999 is read. If there are n numbers to be read by the code. Then the worst case run time is O(n).

 For each of the code segments below, determine an equation for the worst-case computing time T(n) (expressed as a function of n, i.e. 2n + 4) and the order of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site