📌  相关文章
📜  国际空间研究组织 | ISRO CS 2011 |问题 74(1)

📅  最后修改于: 2023-12-03 15:23:03.020000             🧑  作者: Mango

ISRO CS 2011 | Question 74

Introduction

The International Space Research Organization (ISRO) is India's national space agency. It is responsible for the development, design, launch and operation of India's space research and exploration missions. The ISRO CS 2011 is an entrance exam conducted by ISRO for the recruitment of computer programmers.

Question 74

Consider the following recursive function:

f(n) = { 1,                           if (n = 1 or n = 2)
         f(n - 1) + 2f(n - 2) + 3f(n - 3), otherwise }

The value of f(5) is:

(A) 33 (B) 28 (C) 31 (D) 36

Solution

We can solve this problem using recursion. Let's break down the function:

  • If n = 1 or n = 2, f(n) = 1.
  • Otherwise, f(n) = f(n-1) + 2f(n-2) + 3f(n-3).

So, to find the value of f(5), we need to calculate f(4), f(3), and f(2).

f(2) = 1
f(3) = 1
f(4) = f(3) + 2f(2) + 3f(1) = 1 + 2(1) + 3(1) = 6

Now we can find f(5) using the formula f(n) = f(n-1) + 2f(n-2) + 3f(n-3):

f(5) = f(4) + 2f(3) + 3f(2) = 6 + 2(1) + 3(1) = 11

Therefore, the answer is (D) 36.

Markdown
# ISRO CS 2011 | Question 74

## Introduction

The International Space Research Organization (ISRO) is India's national space agency. It is responsible for the development, design, launch and operation of India's space research and exploration missions. The ISRO CS 2011 is an entrance exam conducted by ISRO for the recruitment of computer programmers.

## Question 74

Consider the following recursive function:

f(n) = { 1, if (n = 1 or n = 2) f(n - 1) + 2f(n - 2) + 3f(n - 3), otherwise }


The value of f(5) is:

(A) 33
(B) 28
(C) 31
(D) 36


## Solution

We can solve this problem using recursion. Let's break down the function:

- If n = 1 or n = 2, f(n) = 1.
- Otherwise, f(n) = f(n-1) + 2f(n-2) + 3f(n-3).

So, to find the value of f(5), we need to calculate f(4), f(3), and f(2).

f(2) = 1 f(3) = 1 f(4) = f(3) + 2f(2) + 3f(1) = 1 + 2(1) + 3(1) = 6


Now we can find f(5) using the formula f(n) = f(n-1) + 2f(n-2) + 3f(n-3):

f(5) = f(4) + 2f(3) + 3f(2) = 6 + 2(1) + 3(1) = 11


Therefore, the answer is (D) 36.