Provide a big oh runtime analysis for each of the following
Provide a \"big oh\" run-time analysis for each of the following. When a value of \"n\" is used, it is the size of the input. You may assume max() and min() are constant-time in-line functions. void problem_2a() { cin >> rows >> cols; n = rows * cols; step = n; while (step > 1) for (i = 0; i
Solution
Solved Q2 complete, post multiple question to get the remaining answers
Q2a)
Since we are equation n= rows * cols
rows = cols = sqrt(n)
now the for loops i=0 to rows and j=0 to cols will execute for sqrt(n) * sqrt(n) = n operations
But the given for loops are inside the while loop, which will itself take n iterations, hence the total order = n*n = n^2
Hence the function will be O(n^2)
Q2b)
The first for loop will run for n^2 iterations
The second there are three for loops of length n in cascade, so total function value will be n*n*n=n^3
Hence the bigoh of the function will be n^3
Hence O(n^3) is the final answer
