Compute the factorial function F(n) =! for an arbitrary nonnegative Integer n. n! 1...... (n-1). n = (n-1)!. n for n ≥ 1 and 0! = 0.1 by definition, from which of the following algorithms we can compute F(n) - F(n - 1)?
- If n >= 1 return 1 else return F(n - 1) * n
- If n = 0 return, 1 else return F(n - 1) * n
- If n = 1 return 1 else return F(n - 2) * n
- None of these
Explanation
Factorial is defined as: n! = n × (n - 1)! for n ≥ 1, and 0! = 1.
Recursive algorithm:
- if n = 0 return 1
- else return F(n - 1) * n
To compute F(n) - F(n - 1), first calculate F(n) recursively using this formula, then subtract F(n - 1).
Last verified on 24-03-2026
Related MCQs
ورچوئل میموری میں میموری کے وسائل کن کے درمیان منظم اور مختص کیے جاتے ہیں؟
- Printers
- Processes
- Keyboards
- None of these
اس سوال کو وضاحت کے ساتھ پڑھیں
وی پی این کا بنیادی مقصد کیا ہے؟
- To provide privacy and secure connections over networks
- To delete computer files
- To increase RAM
- None of these
اس سوال کو وضاحت کے ساتھ پڑھیں
ای میل ایڈریس کا ڈومین والا حصہ عام طور پر کس چیز کی نشاندہی کرتا ہے؟
- The email password
- The organization or mail service domain
- The user's phone number
- None of these
اس سوال کو وضاحت کے ساتھ پڑھیں
سرچ انجن کا بنیادی مقصد کیا ہے؟
- To create documents
- To search for information and websites
- To design presentations
- None of these
اس سوال کو وضاحت کے ساتھ پڑھیں
نیٹ ورک کارڈ کے منفرد ہارڈویئر ایڈریس کو کیا کہتے ہیں؟
- IP Address
- MAC Address
- Email Address
- None of these