We are given a code symmetry, that takes an n x n matrix as its argument. It returns true if the matrix is symmetric and false if it is not. The run time of the code is calculated by counting how many times the /= comparison is executed. procedure symmetry(M) for x:=1 to (n-1) for y:=(i+1) to n if mxy /= myx then return false else return true (a) Calculate the best case run time for symmetry (will be a number). (b) Calculate the worst case run time for symmetry (will be a polynomial in n, it will be helpful to draw matrices of different sizes and compare the number of comparisons to find a pattern). (c) Determine the worst case run time in big O notation
We are given a code symmetry, that takes an n x n matrix as its argument. It returns true if the matrix is symmetric and false if it is not. The run time of the code is calculated by counting how many times the /= comparison is executed.
procedure symmetry(M)
for x:=1 to (n-1)
for y:=(i+1) to n
if mxy /= myx then return false
else return true
(a) Calculate the best case run time for symmetry (will be a number).
(b) Calculate the worst case run time for symmetry (will be a polynomial in n, it will be helpful to draw matrices of different sizes and compare the number of comparisons to find a pattern).
(c) Determine the worst case run time in big O notation
(d) Using the following definition of big O notation, prove the answer to (c)
Definition: Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x) is O(g(x)) if there are constants C and k such that whenever x > k. [This is read as “f(x) is big-oh of g(x).”]
Trending now
This is a popular solution!
Step by step
Solved in 3 steps