Question

In: Computer Science

ALGORITHM ANALYSIS AND DESIGN Analyze the given questions and answer accordingly 1.       Given the algorithm to...

ALGORITHM ANALYSIS AND DESIGN

Analyze the given questions and answer accordingly

1.       Given the algorithm to calculate the factorial of ‘n’. Mathematically analyze the given recursive algorithm to find out the time complexity of the algorithm.   

Algorithm F(n)

If n = 0 return 1

Else

Return f(n-1) * n

Solutions

Expert Solution

We want to find the time complexity of the given algorithm.

First case:So from the algorithm, we can see that if the number is 0, it will return 0.Which means the algorithm have one comparison when the value of n is 0.

We can write this as,

for f(0), T(0)=1

Second case:If the number is n, we can observe that it include one comparison to check whether n is 0 or not, then it have one multiplication and one subtraction. And also it require time to perform f(n-1).

We can write this as,

for f(n), T(n)=T(n-1)+3

From the above details we can find the time complexity as,

T(n)=T(n-1)+3 -------(1)

T(n-1)=T(n-2)+3 ------(2)

T(n-2)=T(n-3)+3 -----(3)

T(n-3)=T(n-4)+3 ------(4)

Now substitute (2), (3) and (4) in (1),

T(n)=T(n-2)+6

=T(n-3)+9

=T(n-4)+12

=....

=......

=T(n-k)+3k -----(5)

We know that T(0)=1

We want to find the value of k where n-k=0, which means n=k.

So we write the equation (5) as,

T(n)=T(0)+3n because n=k

T(n) =1+3n

From above we can write that the time complexity of the given algorithm is O(n)

  


Related Solutions

Please answer the following questions, accordingly: 1. What must be the responsibility of government in an...
Please answer the following questions, accordingly: 1. What must be the responsibility of government in an economy? 2. What are the advantages? 3. What are the the disadvantages? 4. Overall, why is it imperative in Real-World terms?
i Choose amazon organization and analyze it accordingly. Attempt all Questions related to your organization. (Note:...
i Choose amazon organization and analyze it accordingly. Attempt all Questions related to your organization. (Note: Questions should be in the serial order with references wherever is required. C. Market tools and Application( MA ) a) Core Marketing Concepts and define value chain b) Use of Branding and video marketing c) E mail Marketing and Social Media Marketing d) Available tools of E Commerce
i Choose amazon business organization and analyze it accordingly. Attempt all Questions related to your organization....
i Choose amazon business organization and analyze it accordingly. Attempt all Questions related to your organization. (Note: Questions should be in the serial order with references wherever is required. B. Market and Cost Analysis (MA) a) Segmentation analysis and strategy. b) Positioning in the marketplace. c) Procurement of goods and Services d) Major customer acquisition techniques, online advertising, ad serving and targeting
i Choose amazon business organization and analyze it accordingly. Attempt all Questions related to your organization....
i Choose amazon business organization and analyze it accordingly. Attempt all Questions related to your organization. (Note: Questions should be in the serial order with references wherever is required. B. Market and Cost Analysis (MA) a) Segmentation analysis and strategy. b) Positioning in the marketplace. c) Procurement of goods and Services d) Major customer acquisition techniques, online advertising, ad serving and targeting
1. Mathematically analyze the given Recurrence Relation and find out the time complexity of the algorithm....
1. Mathematically analyze the given Recurrence Relation and find out the time complexity of the algorithm. T(n) = T(n-1)+1 , if n> 0 1 if n = 0
Design and analyze a divide-and-conquer algorithm for finding the maximum element in a list: L[0: n – 1].
The following submission rules apply:·    For those questions requiring programs, the solutions must be implemented using JavaScript or Java.o Appropriate self-documenting comments in the source code are mandatory, consistent with good programming practices.o Solutions must be provided in plain text so that formatting is not lost.·    All answers must be provided in this document.·    Sources must be given accurate and complete citations sufficient for the instructor to find and confirm them.Design and analyze a divide-and-conquer algorithm for finding the maximum...
subject: International business Q. No. 3 Analyze the following situation and answer the questions given below...
subject: International business Q. No. 3 Analyze the following situation and answer the questions given below Max Marks 10 Should We Allow Global Corporation to Set Up a Factory in our Country? About the business.  Global Corporation is applying for planning permission to build a factory in your country. The factory is expected to be very profitable. 1000 new jobs should be created for assembly-line work. Many of the goods made could be sold abroad. Some of the supplies for the...
We are given an array of n numbers A in an arbitrary order. Design an algorithm...
We are given an array of n numbers A in an arbitrary order. Design an algorithm to find the largest and second largest number in A using at most 3/2n -2 comparisons. (i) describe the idea behind your algorithm in English (3 points); (ii) provide pseudocode (5 points); (iii) analyze the number of comparisons used in your algorithm (2 points).
Answer the following questions using the Toyota Corporation as the focus of your assignment 1) Analyze...
Answer the following questions using the Toyota Corporation as the focus of your assignment 1) Analyze how your company is leveraging social media in their communications strategy. List which social media platforms are currently being used by your company (which may include profiles for specific brands or products), and provide an example demonstrating how the company utilizes social media to offer sensory experiences, engages customers socially, and for industrious purposes. 2) Imagine your company wants to run a campaign to...
Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis...
Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis of the Algorithme lecture
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT