Question

Write a method in JAVA/C++ to solve the Syracuse Sequence using recursion. A Syracuse Sequence is...

Write a method in JAVA/C++ to solve the Syracuse Sequence using recursion. A Syracuse Sequence is a sequence that begins with a number n0 and each element ni of the sequence is ni-1/2 if is ni-1 even and 3*ni-1+1 otherwise. You can write the method in a .docx file (no source code required). Also write the base, and induction clause. Draw the Activation Record (AR) diagram for the first six elements of the series when it starts with 7 (the value of n0).

Homework Answers

Answer #1

CODE IN C++:

#include <iostream>
using namespace std;
int syracuseSequence(int n){
cout << " " <<n <<" ";
if(n==1)
return 1;
  
if(n%2==0)
return syracuseSequence(n/2);
return syracuseSequence(3*n+1);
}
int main()
{
int n;
cout << "Enter a number:";
cin >> n ;
cout<<"Following is the corresponding syracuseSequence:"<<endl;
syracuseSequence(n);
  
}
OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please dont forget the bolded part. Read carefully Write a method in JAVA/C++ to solve the...
Please dont forget the bolded part. Read carefully Write a method in JAVA/C++ to solve the Syracuse Sequence using recursion. A Syracuse Sequence is a sequence that begins with a number n0 and each element ni of the sequence is ni-1/2 if is ni-1 even and 3*ni-1+1 otherwise. You can write the method in a .docx file (no source code required). Also write the base, and induction clause. Draw the Activation Record (AR) diagram for the first six elements of...
Please dont forget to draw the AR diagram and write the base and induction clause Write...
Please dont forget to draw the AR diagram and write the base and induction clause Write a method in JAVA or C++ to solve the Syracuse Sequence using recursion. A Syracuse Sequence is a sequence that begins with a number n0 and each element ni of the sequence is ni-1/2 if is ni-1 even and 3*ni-1+1 otherwise. You can write the method in a .docx file (no source code required). Also write the base, and induction clause. Draw the Activation...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
language: JAVA the Problem Below are a series of problems you need to solve using recursive...
language: JAVA the Problem Below are a series of problems you need to solve using recursive methods. You will write a program that will read commands from an input file, with each command referring to one of the recursive problems to be executed. Each command will be followed (on the same line of input) by the respective parameters required for that problem. (15 points for main method) DescArrayCheck   Write a recursive method that checks whether an array of integers -...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write...
IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT