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.
-
A local postal carrier distributes firstclass letters, advertisements, and magazines. For a certain day, she distributed the following numbers of each type of item. If an item of mail is selected at...
-
Identify and explain a transaction that causes other contributed capital to increase but does not result in any increase in assets or decrease in the liabilities of a corporation.
-
Dale Corporation has the following data: Dale's return on assets is a. \(15 \%\) b. \(12 \%\) c. \(10 \%\) d. \(4 \%\) Net income $22,000 Average total assets $300,000 Interest expense 8,000 Average...
-
Paul Smith is opening a plumbing supply store in University City. He plans to sell plumbing parts and materials to both wholesale and retail customers. Since contractors (wholesale customers) prefer...
-
Osage, Inc., manufactures and sells lamps. The company produces only when it receives orders and, therefore, has no Inventories. The following information is available for the current month: Actual...
-
Rainmaker Environmental Consultants is just finishing its second year of operations. The companys unadjusted trial balance at October 31, 2023, follows. Rainmaker prepares adjustments each October...
-
1. Analyze potential challenges in the process of creating an effective onboarding team. 2. Identify at least two appropriate strategies the on boarding team will use to address resistance to...
-
List some design and implementation rules.
-
What is the traditional legal status of stepparents? How has this begun to change?
-
Identify and explain the various guideline approaches.
-
List some modeling rules.
-
What approach has the law typically taken with regard to the parenting rights of a lesbian co-parent?
-
Using the provided script for simulating trajectories of (St) with the log-normal Black- Scholes dynamics, implement the Monte Carlo method for pricing Asian Calls. Namely, the option payoff is max N...
-
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.
-
The following report was prepared by M. Salvemini, CPA, to accompany unaudited financial statements: We have prepared the statement of net worth, dated November 30, 19X1, that is attached hereto....
-
W.E. Jolson, CPA, has issued the following report on the Bambino Lumber Company's balance sheet: I have audited the balance sheet of Bambino Lumber Co. for the period ended December 31, 19X1. Due to...
-
You have been asked to prepare unaudited financial statements for the Marek Company for the year ended December 31, 19X5. Marek does not want the notes to financial statements to disclose that the...
Study smarter with the SolutionInn App