Consider the problem of computing N!=1·2·3···N.

(a) If Nis an role="math" localid="1658397956489" n-bit number, how many bits long is N!, approximately ( inΘ(·)form)?

(b) Give an algorithm to compute N!and analyze its running time.

Short Answer

Expert verified

The running time complexity of the given algorithm can be analyzed as it runs for n iteration and that is multiplied and the final time complexity O(NlogN).

Step by step solution

01

Introduction

The factorial can be defined as the product of all the numbers between 1 and the given number including the given number. It can be represented as an integer with an exclamation mark.

02

Calculation of bits long with N!

We have,

N!=1·2·3···N.

It is known that,

Log2(N!)=Θ(Nlog2N)

So, N-factorial can be written as,

N!=Θ(Nlog2N)

It can be written as,Θ(n2n)

Given that, N is a n-bit number, then

N!isΘ(n2n)bitslong.

03

Algorithm to compute N!

Normal algorithm flow is shown below,

Factorial(N)If(N==0)Return1ElseReturnNfactorial(N-1)

The running time complexity of the given algorithm can be analyzing as it runs for n iteration and that are multiplied and the final time complexity O(NlogN).

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free