Consider the following algorithms. int add-them (int n, int A[]) { index i,j,k; j=0; for (i...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following algorithms. int add-them (int n, int A[]) { index i,j,k; j=0; for (i 1; in; i++) j=j+A: k=1; for (i=1;i; i++) k=k+k; return j+k; } int any equal (int n, int A[ ][ ]) { index i,j,k,m; for (i=1;in i++) for (j=1:j j++) for (k=1; kn; k++) for (m =1: mmm++) if (AA[k][m] && !(i == k &&j==m)) return 1; return 0; Note: The array parameter A[][] in any equal is an n x n two-dimensional array. For example, when n 5, then A is a 5 x 5 two-dimensional array. (a) Let's say that the basic operation of any equal is the evaluation of the if-statement, ie.. if (A[i][j]==A[k][m] && !(i==k&&j==m)) What is the worst-case time complexity of any equal when A is an n x n two-dimensional array? (b) Draw an example of a two-dimensional array that causes any equal to run in the worst-case when n=5. (c) What is the best-case time complexity of any equal? (d) Draw an example of a two-dimensional array that causes any equal to run in the best-case when n=5. (e) Does any equal have an every-case time complexity? Why or why not? Consider the following algorithms. int add-them (int n, int A[]) { index i,j,k; j=0; for (i 1; in; i++) j=j+A: k=1; for (i=1;i; i++) k=k+k; return j+k; } int any equal (int n, int A[ ][ ]) { index i,j,k,m; for (i=1;in i++) for (j=1:j j++) for (k=1; kn; k++) for (m =1: mmm++) if (AA[k][m] && !(i == k &&j==m)) return 1; return 0; Note: The array parameter A[][] in any equal is an n x n two-dimensional array. For example, when n 5, then A is a 5 x 5 two-dimensional array. (a) Let's say that the basic operation of any equal is the evaluation of the if-statement, ie.. if (A[i][j]==A[k][m] && !(i==k&&j==m)) What is the worst-case time complexity of any equal when A is an n x n two-dimensional array? (b) Draw an example of a two-dimensional array that causes any equal to run in the worst-case when n=5. (c) What is the best-case time complexity of any equal? (d) Draw an example of a two-dimensional array that causes any equal to run in the best-case when n=5. (e) Does any equal have an every-case time complexity? Why or why not?
Expert Answer:
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
"internet radios" for streaming audio, and personal video recorders and players. Describe design and evaluation processes that could be used by a start-up company to improve the usability of such...
-
Python and most Python libraries are free to download or use, though many users use Python through a paid service. Paid services help IT organizations manage the risks associated with the use of...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
At December 31, 2018, Landy Products has cash of $24,000, receivables of $18,000, and inventory of $80,000. The companys equipment totals $182,000. Landy owes accounts payable of $22,000 and...
-
Access the annual report of Canadian Tire Corporation for the year ended December 31, 2011, from the company's website or SEDAR (www.sedar.com). According to the annual report, the company operates...
-
Find the threshold energy needed to produce c ++ (uuc) with a beam on a hydrogen target.
-
Identify the four components of an ecosystem. After you do this try to visualize the interactions of these four components of an ecosystem as illustrated by Figure 2. 2 in the textbook. Does this...
-
Kelly Realty loaned money and received the following notes during 2012. Requirements For each note, compute interest using a 360-day year. Explanations are not required. 1. Determine the due date and...
-
1. Assuming firms in a market face a linear downward-sloping demand curve and constant marginal and average costs, carefully explain where equilibrium price would be if it were a competitive market....
-
Bean There Inc. manufactures coffee makers. Selected budget and actual information for 2020 is provided below: Budget Information Required: a. b. b. Units sold Sales in dollars Average selling price...
-
Louise Kane executed a will that left her entire estate to her grandson. When her grandson died, Louise executed a new will that named her great-grandson as her sole beneficiary and specifically...
-
As a pharmacist is administering a flu vaccination to a patient, the patient asks if the vaccine is considered a drug and approved by the FDA prior to marketing. What would be the correct information...
-
A patient who has recently been dispensed a prescription medication angrily confronts the pharmacist. The patient has read the CMI included with the product and notes that the drug is not indicated...
-
The consumer price index in the United States (base period 19821984) was 226.229 in 2012 and 229.324 in 2013. Calculate the inflation rate from 2012 to 2013.
-
For fifty years, the Soviet Union made and sold Stolichnaya vodka and licensed its trademark for use in the United States. After the Soviet Union collapsed, the state enterprise that had managed the...
-
C1. Consider the following truss structure: 45 20kN 6m 6m Figure 5 Given that the horizontal reaction at joint A is zero. a) Determine the horizontal reaction at joint G. b) Determine the vertical...
-
How does the organizational structure of an MNC influence its strategy implementation?
-
Consider again the two ways in which we can view the producers profit maximization problem. A: Suppose a homoethetic production technology involves two inputs, labor and capital, and that its...
-
In 2005, the U.S. Congress passed a bill to extend daylight savings time earlier into the spring and later into the fall (beginning in 2007). The change was made as part of an Energy Bill, with some...
-
In this exercise we explore some technical aspects of general equilibrium theory in exchange economies and Robinson Crusoe economies. Unlike in other problems, parts A and B are applicable to both...
-
What encoding scheme is extensive to represent all the characters of all the languages in the world?
-
What is hardware?
-
What is pseudocode?
Study smarter with the SolutionInn App