Q1: Analyze the following Algorithms. Find their running time and asymptotic notations. int fun(int n) {...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Q1: Analyze the following Algorithms. Find their running time and asymptotic notations. int fun(int n) { Algorithm 1 int count = 0; ; for (int i = 0; i < n; i++) { for (int j = i; j> 0; j--) { count = count + 1; } } return count; void fun(int n, int arr[]) { int i = 0, j = 0; for(; i < n; ++i) { while(j <n && arr[i] < arrj) { j++; } } Algorithm 2 %3D int fun1 (int n) { if (n <= 1) return n; Algorithm 3 return 2*fun1(n-1); } int fun2(int n) { if (n <= 1) return n; Algorithm 4 return fun2(n-1) + fun2(n-1); double foo (int n) { int i; Algorithm 5 double sum; if (n 0) return 1.0; = = else { sum = 0.0; for (i = 0; i < n; i++) sum += foo (i); return sum; } } Q1: Analyze the following Algorithms. Find their running time and asymptotic notations. int fun(int n) { Algorithm 1 int count = 0; ; for (int i = 0; i < n; i++) { for (int j = i; j> 0; j--) { count = count + 1; } } return count; void fun(int n, int arr[]) { int i = 0, j = 0; for(; i < n; ++i) { while(j <n && arr[i] < arrj) { j++; } } Algorithm 2 %3D int fun1 (int n) { if (n <= 1) return n; Algorithm 3 return 2*fun1(n-1); } int fun2(int n) { if (n <= 1) return n; Algorithm 4 return fun2(n-1) + fun2(n-1); double foo (int n) { int i; Algorithm 5 double sum; if (n 0) return 1.0; = = else { sum = 0.0; for (i = 0; i < n; i++) sum += foo (i); return sum; } }
Expert Answer:
Answer rating: 100% (QA)
Algorithm 1 int Funint n int count 0 forint i0i ni forint jij0 j count 1 return count Findi... View the full answer
Related Book For
Discrete Mathematics and Its Applications
ISBN: 978-0073383095
7th edition
Authors: Kenneth H. Rosen
Posted Date:
Students also viewed these algorithms questions
-
Analyze the following Algorithms. Find their running time and asymptotic notations. Algorithm 1 int fun(int n) int count 0; for (int i 0; i < n; i++) for (int j= i; j> 0; j-) count = count + 1;...
-
The transactions for Fun Time Daycare, Inc., for the month of May 2012 are posted in the following T-accounts. Requirements 1. Calculate account balances at May 31, 2012. 2. Prepare the trial balance...
-
Analyze the worst-case time complexity of the algorithm you devised in Exercise 29 of Section 3.1 for locating a mode in a list of nondecreasing integers.
-
For the charge configuration of Prob. 2.15, find the potential at the center, using infinity as your reference point.
-
What are the components of an ethics program, and how effective are such programs at promoting ethical behavior?
-
Is pricing its vehicles similar to the competition a good strategy for Honda?
-
After the positrons were annihilated, the energy density of the universe was dominated by the photons and the neutrinos. Show that the energy density in that era was given by \(u_{\text {total...
-
Bonds 1. Municipal Bonds - Municipal bonds are haircut per Exhibit 1 based on both their time to maturity and scheduled maturity at date of issue. 2. Corporate Bonds - Corporate bonds are haircut...
-
Video - Youtube -Lease Accounting Basic Example To Determine Lease Type (Capital Vs Operating Lease) https://www.youtube.com/watch?v=slNrpKODlSw
-
FREE-CASH-FLOWS-BASED VALUATION. In Problem, we projected financial statements for Wal-Mart Stores, Inc. (Walmart) for Years +1 through +5. The data in Exhibits 13 (see pages 985987) include the...
-
Assume that you are selling a complete line of weather-resistant patio, pool, and deck furniture to a large hotel to replace all of its current furniture. The total cost will be $375,000. You expect...
-
analyze and discuss the organizational design and structure of Google? 2) analyze and discuss how google manages ethical issues, conflict, and managerial challenges. 3) analyze and discuss whether...
-
Warehouse Plc purchases and resells television sets. It has a monthly demand of 24,000 units. It currently orders the television sets in batches of 12,000 and each order incurs a fixed cost of 400....
-
Beverage Inc, is an S corporation which Carries accumulated earnings and profits from its past years as a C corporation. The balance in the accumulated E&P account at the beginning of 2018 was...
-
The risk-free return is 5.79 percent, the expected return on the market is 13.8 percent, the expected real return for Litchfield Design stock is 3.64 percent, and the beta for Litchfield Design stock...
-
Discuss the appropriate uses of a focus group. What do market researchers use focus groups for? What are the advantages and disadvantages? Who is involved, how does a focus group typically work?...
-
You would like to vacation in Hawaii for one week each year. You can buy a time share for a vacation home in Hawaii for $18,500 today and a maintenance fee of $600 per year starting next year. You...
-
The executor of Gina Purcells estate has recorded the following information: Assets discovered at death (at fair value): Cash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
-
Devise an algorithm that finds the first term of a sequence of positive integers that is less than the immediately preceding term of the sequence.
-
How much time does an algorithm using 250 operations need if each operation takes these amounts of time? a) 106 s b) 109 s c) 1012 s
-
Prove that there is no positive integer n such that n2 + n3 = 100.
-
Based on the photographs in Figure 26.13, in which segment(s) is the Antp gene normally expressed? Figure 26.13: (a) Normal fly (b) Antennapedia mutant
-
The bush baby, a small African mammal, is a remarkable jumper. Although only about 8 inches long, it can jump, from a standing start, straight up to a height of over 7 feet! Use the particle model to...
-
Hicham El Guerrouj of Morocco holds the world record in the 1500 m running race. He ran the final 400 m in a time of 51.9 s. What was his average speed in mph over the last 400 m? A. 14.2 mph B. 15.5...
Study smarter with the SolutionInn App