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

icon
Related questions
Question

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).”]

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Problems on Amortized Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, data-structures-and-algorithms and related others by exploring similar questions and additional content below.