Recursive function could result in an infinite loop

Assignment Help C/C++ Programming
Reference no: EM13916791

Overview: For problem 1(a) of this assignment, you will need a C++ compiler. In order to receive credit, your program must compile and run; and you must provide the actual source code file so that I can compile and run your program (e.g. the file you modified ending in .cpp). Examples on how to import existing files into your compiler are provided in the file called Importing Source Code.pdf. The remaining problems for the assignment must be written up within a single Microsoft Word document. You must include your name and course number within all files that you submit, including source code files as a comment at the top of each file that you create or
modify.

1. Recursion. Read the assigned chapter and notes for Week 1 located in the Learning Activities area in Blackboard. Then provide solutions for the following:

(a) Download the f.cpp file, then using the definition below, implement the details of a recursive function called f(n). This function can be directly translated into C/C++ from the following mathematical definition:

(1) 2 1 0
(1) 2 1 0
0 0
( )
f n n n
f n n n
n
f n

The function must be implemented based on the mathematical definition provided above.

Note: For this program, the function must use recursion. You only need to modify the provided file by adding the necessary code to implement the TODO areas as noted in the comments. Everything else in the program should remain the same.

Output: The output for this program once the function is implemented will be as follows:

f(-44) is 1936
f(-20) is 400
f(-1) is 1
f(0) is 0
f(1) is 1
f(13) is 169
f(20) is 400
f(50) is 2500
f(44) is 1936

** Press any key to continue **

(b) Briefly explain how the following recursive function could result in an infinite loop and what you could do to correct this:

(c) Perform an Internet search and provide a brief description (at least a paragraph with four to five sentences) of an example of a practical use for recursion. For example, the practical use you mention should be something other than simple function implementations such as factorial, the power of a number, Fibonacci, etc. The description should be in your own words. Include the reference to your source or sources in APA format at the end of your description.

2. Complexity Analysis. Begin by reading the assigned chapter located in the Learning Activities area in Blackboard. Then answer the following questions:

(a) Briefly explain the difference between big-Ω (Omega) and big-O notation. Also provide the mathematical definitions of each.

(b) What is the asymptotic complexity (or big-O) of the following code block? Briefly explain why.

Note: No programming is necessary for this problem. Just tell me what the big-O of the function, and provide a couple of sentences explaining how you arrived at the solution.

for (int i=0; i < n; i++)
{
for (int j=0; j < n; j++)
{
a[i][j]=0;
for (int k=0; k < n; k++)
{
a[i][j] += b[i][k] * c[k][j];
}
}
}

Reference no: EM13916791

Questions Cloud

Balance in the investment account : Required: What is the c as of December 31, 2009?
Calculate the one-sample t statistic : More critical values. You have an SRS of size 30 and calculate the one-sample t statistic. What is the critical value t* such that t has probability 0.025 to the right of t*?
What is a strategic business plan : What is a strategic business plan? Why is this plan important to an organization's long-term success? What role does innovation play in developing a strategic business plan?
The purpose of cryptography and take a position : Explain, in your own words, the purpose of cryptography and take a position on whether or not you believe encryption is sufficiently utilized in organizations today. Provide a rationale with your response. Describe the differences between symmetric a..
Recursive function could result in an infinite loop : Briefly explain how the following recursive function could result in an infinite loop and what you could do to correct this:
What we can learn from geese : What We Can Learn From Geese. When geese fly in formation, we can't help but look up and marvel at their beauty. But their behavior also represents successful teamwork patterns that have evolved over the ages.
Temporary differences produce current or noncurrent deferred : Indicate whether the following temporary differences produce current or non-current deferred tax assets or deferred tax liabilities (considered independently).
Management team for ppq parts manufacturing company : As part of the management team for PPQ Parts manufacturing company, you are tasked with selecting the best software packages for the firm's materials requirements planning (MRP), capacity requirement planning (CRP), and enterprise resource plannin..
Rebalancing a binary search tree : Your task is to write a class RebalancingTree that extends the attached BST class. You should override the insert method in BST. Your overriding method should first call the method it is overriding

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Economy of kenya has a budget deficit

The economy of Kenya has a budget deficit of KSH 500B. This deficit is likely to be funded through domestic borrowing and taxation. Using an appropriate model, explain the macroeconomic implications of such a move.

  Write a program that counts and prints the number of lines

Write a program that counts and prints the number of lines, words, and letter frequencies in its input. To where it bent in the undergrowth; would produce the output.

  Implement uniform random number generator

Implement Uniform Random Number generator and Generate 1000 Random number between 0 an 10000.

  Insert the missing code in the c program

You are to insert the missing code in the C program given for combinational equivalence checking. This program will interface with the CUDD package and will parse netlist files in ISCAS85 circuit format. Next, BDDs will be created for each circuit an..

  Define a 2-element array of characters

Write an if statement that sets the variable age to 21 when the flag variable adult is set and define a 2-element array of characters named alpha initialized with the characters P, Q.

  How to modify this program

Directions are below the pasted code.

  The mean and standard deviation

How do i write a program in c++ that use functions max, min, the total numbers, the mean and standard deviation to read a file text and return these values from the file text. note the file text has random numbers. note im not suppose to use arrays.

  Write a loop that fills a vector

Write a loop that fills a vector V with ten  different  random numbers between 1 and 100. output must actually display the random numbers to get credit.

  Write a method insertat that takes four parameters

Write a method, insertAt, that takes four parameters: an array of integers; the length of the array; an integer, say insertItem; and an interger, say, index.

  Program should read in the file and place periods

Create a C++ program that will read this file and correct errors in the English syntax of the file. The program should Read in the file and Place periods at the end of all sentences throughout this file

  Problem related to calculating average in program

Here's the program i must do: 3 evaluators will evaluate 4 parameters ( just name them parameter1, parameter2 ...) the program must ask the evaluators to input those parameters but as letters (N=1,M=2,S=3,B=4,E=5) then I have to do the average for..

  Write a program that uses a loop to display projected rates

Write a program that will convert US dollar amounts to Canadian dollar (1 CND = 0.92 USD). Format your currency amounts in two decimal places and trailing zeros.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd