1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
alekssr [168]
3 years ago
5

Is recursion ever required to solve a problem? What other approach can you use to solve a problem that is repetitive in nature?

Computers and Technology
1 answer:
Setler79 [48]3 years ago
8 0

Answer:

No you can not tell that recursion is ever required to solve a problem.

Recursion is required when in the problem, the solution of the input depends on the solution of the subsets of the input.

Iteration is also another form of repetitive approach we follow to solve that kind of problems.

But the difference between recursion and iteration is :

  • In recursion we call the function repeatedly to return the result to next level.
  • In iteration certain bunch of instructions in a loop are executed until certain conditions met.

Explanation:

For example in the Fibonacci sequence problem, to find f_{n}, we need to compute f_{n-1} and f_{n-2} before that.

  • In case of recursion we just call the method Fibonacci(n) repeatedly only changing the parameter Fibonacci(n-1), that calculates the value and return it.

                           Fibonacci(n)

                           1. if(n==0 or n==1)

                           2.       return 1.

                           3.else

                           4.      return( Fibonacci(n-1)+Fibonacci(n-1) )

  • But in case of iteration we run a loop for i=2 to n, within which we add the value of current f_{i-1} and f_{i-2} to find the value of f_{i}

                           Fibonacci(n)

                           1. if(n<=2)

                           2.    result = 1

                           3.     else

                           4. result1 =1 and result2=1.

                           5.      {  result = result1 +result2.

                           6.         result1= result2.

                           7.         result2 = result.

                           8.      }

                           9.  output result.

You might be interested in
Write an application that displays every perfect number from 1 through 1,000. A perfect number is one that equals the sum of all
matrenka [14]

Answer:

Written in Python

for num in range(1,1001):

    sum=0

    for j in range(1,num+1):

         if num%j==0:

              sum = sum + j

                   if num == sum:

                        print(str(num)+" is a perfect number")

Explanation:

This line gets the range from 1 to 1000

for num in range(1,1001):

This line initializes sum to 0 for each number 1 to 1000

    sum=0

This line gets the divisor for each number 1 to 1000

    for j in range(1,num+1):

This following if condition line checks for divisor of each number

<em>          if num%j==0: </em>

<em>               sum = sum + j </em>

The following if condition checks for perfect number

                   if num == sum:

                        print(str(num)+" is a perfect number")

5 0
3 years ago
Can someone tell me what all of these are?
Allisa [31]

Answer:

parts of a camera

Explanation:

5 0
3 years ago
This is the question
nikdorinn [45]

Answer:

I dont know it sorry

Explanation:

i would help u

4 0
2 years ago
Write a program that declares an array named myArray with 8 components of the type int. Initialize the array to 8 values that th
Savatey [412]

Answer:

#include <iostream>

using namespace std;

void filterEvens(int myArray[]) {

   for (int i = 0; i < 8; ++i) {

     if(myArray[i]%2==0){

         cout<<myArray[i]<<" ";

     }

  }

}

int main(){

   int myArray[8];

   for(int i =0;i<8;i++){

       cin>>myArray[i];

   }

   filterEvens(myArray);

   return 0;

}

Explanation:

The solution is provided in C++

#include <iostream>

using namespace std;

The function filerEvens is defined here

void filterEvens(int myArray[]) {

This iterates through the elements of the array

   for (int i = 0; i < 8; ++i) {

This checks if current element is an even number

     if(myArray[i]%2==0){

If yes, this prints the array element

         cout<<myArray[i]<<" ";

     }

  }

}

The main begins here

int main(){

This declares an integer array of 8 elements

   int myArray[8];

The following iteration allows input into the array

<em>    for(int i =0;i<8;i++){</em>

<em>        cin>>myArray[i];</em>

<em>    }</em>

This calls the defined function filter Evens

   filterEvens(myArray);

   return 0;

}

6 0
3 years ago
What are the basic steps in creating a new program
ladessa [460]
<span>first make a text file, then write the framework or(scripts for your program). Then write Your Instruction and save Your Program. After you've done that, get and install java jdk(its like a development tool). Finally c<span>opy the path(text file) to the Java tools(jdk)

</span></span>
3 0
3 years ago
Other questions:
  • You're working at a large industrial plant and notice a tag similar to the one shown in the figure above. Which of the following
    5·1 answer
  • Mica's creating his web page with a software that is free of charge for the first month. If he likes the program, he will have t
    7·2 answers
  • What would be a reason for using a workstation rather than a personal computer?
    7·1 answer
  • What is a lan adapter
    7·2 answers
  • A(n) ____________________ is hardware or software that blocks or allows transmission of information packets based on criteria su
    13·1 answer
  • What is the use of an NDP?
    13·1 answer
  • Which of the following scenarios describes an IT professional using the Internet and computer system access in an unprofessional
    7·1 answer
  • What is the function of ROM?
    10·1 answer
  • In HTML, an opening tag and its closing tag must appear on the same line. True Or False​
    12·1 answer
  • Are programs that understand physics and/or hardware embedded? for example, one that uses finite-element methods to predict flui
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!