• What input or parameter value impacts the number of times the recursive function will be called. • Give three specific examples of input/parameter values and, for each, state the number of times the recursive function will be called. • Devise a formula with respect ton that describes the number of times the recursive function will be called, where n is either the value passed or some property of the value passed (e.g. n might be the length of a string of the size of an array).

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
What input or parameter value impacts the number of times the recursive function will
be called.
• Give three specific examples of input/parameter values and, for each, state the number
of times the recursive function will be called.
• Devise a formula with respect to n that describes the number of times the recursive
function will be called, where n is either the value passed or some property of the value
passed (e.g. n might be the length of a string of the size of an array).
Transcribed Image Text:What input or parameter value impacts the number of times the recursive function will be called. • Give three specific examples of input/parameter values and, for each, state the number of times the recursive function will be called. • Devise a formula with respect to n that describes the number of times the recursive function will be called, where n is either the value passed or some property of the value passed (e.g. n might be the length of a string of the size of an array).
permute.cpp x +
permute.cpp > f permute
1 #include <iostream>
2 #include <string>
3
using namespace std;
4
5
int call_count = 0;
6
7 void permute (const string& str, size_t pos) {
V
8
9
call_count++;
string s1 = str.substr(0, pos); // fixed part
10 string s2 = str.substr(pos); // variable part
DWN = 6
11
12
13 ✓
14
15
16
17
18
19
20 }
21
// Finds all permutations of the given string (assumes that all characters
22 // in the string are unique).
23
24
2
25
26
27
28
29
30
31
32
33
34
Y
V
if (s2.size()) { // if there is a variable part
for (size_t i = 0; i < s2.size(); i++) {
}
permute(s1 + s2, pos + 1);
s2 = s2.substr(1) + s2.substr(0, 1); // move first character to end
void permute (const string& str) {
permute(str, 0);
}
}
else
cout << s1 << endl; // no variable part, output the string
int main () {
string s;
cout << "String: ";
cin >> s;
permute(s);
cout << "Call count: <<< call_count << endl;
return 0;
Transcribed Image Text:permute.cpp x + permute.cpp > f permute 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 int call_count = 0; 6 7 void permute (const string& str, size_t pos) { V 8 9 call_count++; string s1 = str.substr(0, pos); // fixed part 10 string s2 = str.substr(pos); // variable part DWN = 6 11 12 13 ✓ 14 15 16 17 18 19 20 } 21 // Finds all permutations of the given string (assumes that all characters 22 // in the string are unique). 23 24 2 25 26 27 28 29 30 31 32 33 34 Y V if (s2.size()) { // if there is a variable part for (size_t i = 0; i < s2.size(); i++) { } permute(s1 + s2, pos + 1); s2 = s2.substr(1) + s2.substr(0, 1); // move first character to end void permute (const string& str) { permute(str, 0); } } else cout << s1 << endl; // no variable part, output the string int main () { string s; cout << "String: "; cin >> s; permute(s); cout << "Call count: <<< call_count << endl; return 0;
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning