Purchase Solution

Examples of recursion in C++

Not what you're looking for?

Ask Custom Question

A. What is direct recursion?

b. What is tail recursion?

c. Suppose hat intArray is an array of integers, and length specifies the number of elements in intArray. Also suppose that low and high are two integers such that 0 <= low < length. 0 <= high < length, and low < high. That is, low and high are two indices in intArray. Write a recursive definition that reverses the elements in intArray between low and high.

d. please see the attachment.

Attachments
Purchase this Solution

Solution Summary

This solution provides a couple straight-forward examples of recursion in C++. It also explains how the recursion is working.

Solution Preview

Direct recursion is when recursion is obtained through a function directly calling itself. This in in constrast to indirect recursion which happens when function A calls function B which then calls function A again.

Tail recursion is a special form of recursion in which the recursive call is at the end of the function body. The following is an example of tail recursion:

<pre>
function count(int x) {
if (x == 0) {
print x;
} else {
count(x-1);
}
}
</pre>

Notice that the call back into the function itself is at the of the body of the ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.