978-1337102087 Chapter 15

subject Type Homework Help
subject Pages 9
subject Words 128
subject Authors D. S. Malik

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 1
1. The following is a valid recursive definition to determine the factorial of a non-negative integer.
0! = 1
1! = 1
n! = n * (n - 1)! if n > 0
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
1036
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
2. In a recursive function, the base case stops the recursion.
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
1037
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
3. With recursion, the base case must eventually be reduced to a general case.
a.
True
b.
False
ANSWER:
False
POINTS:
1
REFERENCES:
1037
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
4. The following is an example of a recursive function.
void print(int x)
{
if (x > 0)
{
cout << x << " " ;
print (x - 1);
page-pf2
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 2
}
}
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
1037
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
5. Every call to a recursive function requires the system to allocate memory for the local variables and formal parameters.
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
1038
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
6. Infinite recursions execute forever on a computer.
a.
True
b.
False
ANSWER:
False
POINTS:
1
REFERENCES:
1038-1039
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
7. You can use a recursive algorithm to find the largest element in an array.
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
1039
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
page-pf3
Name:
Class:
Date:
page-pf4
Name:
Class:
Date:
b.
Statements in Lines 3 and 4.
c.
Statements in Lines 5 and 6.
d.
Statements in Lines 3, 4, and 5.
ANSWER:
b
POINTS:
1
REFERENCES:
1036-1037
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
PREFACE NAME:
foo
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
12. Consider the accompanying definition of a recursive function. Which of the statements represent the general case?
a.
Statements in Lines 1-6
b.
Statements in Lines 3 and 4
c.
Statements in Lines 4, 5, and 6
d.
Statements in Lines 5 and 6
ANSWER:
d
POINTS:
1
REFERENCES:
1036-1037
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
PREFACE NAME:
foo
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
page-pf5
Name:
Class:
Date:
page-pf6
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 6
cout << recFunc(10) << endl;
a.
10
b.
11
c.
100
d.
110
ANSWER:
a
POINTS:
1
REFERENCES:
1037
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
PREFACE NAME:
recFunc
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
17. Consider the following definition of the recursive function print.
void print(int num)
{
if (num > 0)
{
cout << num << " ";
print(num - 1);
}
}
What is the output of the following statement?
print(4);
a.
0 1 2 3 4
b.
1 2 3 4
c.
4 3 2 1
d.
4 3 2 1 0
ANSWER:
c
POINTS:
1
REFERENCES:
1037
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
18. Tracing through ____ recursion is more tedious than tracing other recursive forms.
a.
direct
b.
indirect
c.
tail
d.
iterative
ANSWER:
b
POINTS:
1
REFERENCES:
1038
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
page-pf7
Name:
Class:
Date:
page-pf8
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 8
22. Consider the accompanying definition of the recursive function mystery. Given the declaration:
int alpha[5] = {1, 4, 5, 8, 9};
what is the output of the following statement?
cout << mystery(alpha, 0, 4) << endl;
a.
1
b.
18
c.
27
d.
35
ANSWER:
c
POINTS:
1
REFERENCES:
1039-1041
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
PREFACE NAME:
mystery
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
23. Consider the following definition of the recursive function mystery.
int mystery(int first, int last)
{
if (first > last)
return 0;
else if (first == last)
return first;
else
return first + mystery(first + 1, last - 1);
}
What is the output of the following statement?
cout << mystery(6, 10) << endl;
a.
13
b.
21
c.
40
d.
42
ANSWER:
b
POINTS:
1
REFERENCES:
1043-1044
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:42 PM
DATE MODIFIED:
10/5/2016 1:42 PM
24. Consider the following definition of the recursive function mystery.
int mystery(int num)
{
page-pf9
Name:
Class:
Date:
if (num <= 0)
return 0;
else if (num % 2 == 0)
return num + mystery(num 1);
else
return num * mystery(num 1);
}
What is the output of the following statement?
cout << mystery(5) << endl;
a.
50
b.
65
c.
120
d.
180
ANSWER:
a
POINTS:
1
REFERENCES:
1043-1044
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM
page-pfa
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 10
cout << puzzle(3, 7) << endl;
a.
10
b.
21
c.
42
d.
420
ANSWER:
c
POINTS:
1
REFERENCES:
1043-1044
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
PREFACE NAME:
puzzle
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM
27. Which of the following function headings can be used for a recursive definition of a function to calculate the nth
Fibonacci number?
a.
void rFibNum(int a, int b)
b.
bool rFibNum(int a, int b)
c.
bool rFibNum(int a, int b, int n)
d.
int rFibNum(int a, int b, int n)
ANSWER:
d
POINTS:
1
REFERENCES:
1044
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM
28. How many needles are used in the Tower of Hanoi problem?
a.
one
b.
two
c.
three
d.
four
ANSWER:
c
POINTS:
1
REFERENCES:
1047
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM
29. Which of the following rules should you follow to solve the Tower of Hanoi problem?
a.
Only two disks can be moved at a time.
b.
You can remove disks only from the first needle.
c.
The removed disk must be placed on a smaller disk.
d.
A smaller disk can be placed on top of a larger disk.
ANSWER:
d
page-pfb
Name:
Class:
Date:
page-pfc
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 12
F(n) = F(n - 1) + 1 if n > 1
The value of F(3) is ____________________.
ANSWER:
5
POINTS:
1
REFERENCES:
1036
QUESTION TYPE:
Completion
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM
34. The recursive algorithm must have one or more base cases, and the general solution must eventually be reduced to
a(n) ____________________.
ANSWER:
base case
POINTS:
1
REFERENCES:
1037
QUESTION TYPE:
Completion
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM
35. Recursive algorithms are implemented using ____________________ functions.
ANSWER:
recursive
POINTS:
1
REFERENCES:
1037
QUESTION TYPE:
Completion
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM
36. Consider the following code.
int fact(int num)
{
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
The function fact is an example of a(n) ____________________ recursive function.
ANSWER:
tail
POINTS:
1
REFERENCES:
1037-1038
QUESTION TYPE:
Completion
page-pfd
Name:
Class:
Date:
page-pfe
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 14
41. In the Tower of Hanoi problem, if needle 1 contains three disks, then the number of moves required to move all three
disks from needle 1 to needle 3 is ____________________.
ANSWER:
7
POINTS:
1
REFERENCES:
1049
QUESTION TYPE:
Completion
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:43 PM
DATE MODIFIED:
10/5/2016 1:43 PM

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.