Question

In: Computer Science

Design in pseudo code a linear recursive version of Tetranacci calculators. Tetranacci numbers are a more...

Design in pseudo code a linear recursive version of Tetranacci calculators.

Tetranacci numbers are a more general version of Fibonacci numbers and start with four predetermined terms, each term afterwards being the sum of the preceding four terms. The first few Tetranacci numbers are: 0, 0, 0, 1, 1, 2, 4, 8, 15, 29, 56, 108, 208, 401, 773, 1490, …

Solutions

Expert Solution

Below is the code in C++ to print tetranacci numbers:


#include <iostream>

using namespace std;

int main()
{
int i, n;
cout<<"Enter n: "; //Enter the number of tetranacci numbers you want
cin>>n;
int a[n+4];
  
a[0] = a[1] = a[2] = 0; // Define the first four elements as we need them to calculate sum
a[3] = 1;
  
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]; // Print first four elements
  
for(i = 4; i <= n; i++) // Run loop from 4th element to nth element
{
a[i] = a[i-1] + a[i-2] + a[i-3] + a[i-4]; // value of each element is equal to sum of its previous four elements
cout<<" "<<a[i];
}
  
return 0;
}


Related Solutions

Design in pseudo code a multiple recursive version of Tetranacci calculators. Tetranacci numbers are a more...
Design in pseudo code a multiple recursive version of Tetranacci calculators. Tetranacci numbers are a more general version of Fibonacci numbers and start with four predetermined terms, each term afterwards being the sum of the preceding four terms. The first few Tetranacci numbers are: 0, 0, 0, 1, 1, 2, 4, 8, 15, 29, 56, 108, 208, 401, 773, 1490, …
Design in java a multiple recursive version of Tetranacci calculators. You will calculate Tetranacci(5), Tetranacci(10) and...
Design in java a multiple recursive version of Tetranacci calculators. You will calculate Tetranacci(5), Tetranacci(10) and measure the corresponding run times. (for instance, Tetranacci(10) returns 56). You can use Java’s built-in time function for finding the execution time.
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
design two algorithms, an iterative version and a recursive version , for finding the min and...
design two algorithms, an iterative version and a recursive version , for finding the min and max values in an array of n numbers A.) a iterative version B.) a recursive version derive the time efficiency functions (or time function in terms of n) for each, analyze each function, and compare and discuss the results of the analysis
Write a recursive algorithm in pseudo-code to compute the “power list” of a given list of...
Write a recursive algorithm in pseudo-code to compute the “power list” of a given list of integers. Assume that the List type has members: int List.length returns the length of the list. void List.push(T n) pushes an element n to the front of the list T List.pop() pops an element from the front of the list. List$$ List$$.concat(List$$ other) returns the concatenation of this list with other. Explain in plain English the reasoning behind your algorithm. Power Lists should be...
In pseudo-code, design an algorithm for finding baking a cake.
In pseudo-code, design an algorithm for finding baking a cake.
Java String search Design and implement a recursive version of a binary search.  Instead of using a...
Java String search Design and implement a recursive version of a binary search.  Instead of using a loop to repeatedly check for the target value, use calls to a recursive method to check one value at a time.  If the value is not the target, refine the search space and call the method again.  The name to search for is entered by the user, as is the indexes that define the range of viable candidates can be entered by the user (that are...
Describe in pseudo-code, a linear-time algorithm for reversing a queue Q. To access the queue, you...
Describe in pseudo-code, a linear-time algorithm for reversing a queue Q. To access the queue, you are only allowed to use the basic functions of the queue ADT defined as follows (Hint: Using a stack, the basic stack functions defined in the textbook and in the class). class Queue { public: int size(); bool isEmpty(); Object front(); void enqueue(Object o); Object dequeue(); };
*Please give the answers in pseudo code 1) Design an algorithm that will receive two integer...
*Please give the answers in pseudo code 1) Design an algorithm that will receive two integer items from a terminal operator, and display to the screen their sum, difference, product and quotient. Note that the quotient calculation (first integer divided by second integer) is only to be performed if the second integer does not equal zero. 2) Design an algorithm that will read two numbers and an integer code from the screen. The value of the integer code should be...
1. Here is a pseudo-code of a program that takes two non-negative numbers X and Y...
1. Here is a pseudo-code of a program that takes two non-negative numbers X and Y as its inputs and outputs a number Z. Write this program in C. What does this program do? Explain how it computes the output Z from its inputs X and Y. Determine the big-Oh of this program in terms of its input sizes.                                                                 f (int x, int y) {      z = 0; k = y; w = x;      while (k != 0) {           if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT