Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 14, Problem 1PP
The formula for computing the number of ways of choosing r different things from a set of n things is the following:
C(n, r)=n!/(r! *(n−r)!)
The factorial function n! is defined by
n!=n*(n−1)*(n−2)*…*1
Discover a recursive version of this formula and write a recursive function that computes the value of the formula. Embed the function in a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write the definition of a recursive function
int simpleSqrt(int n)
The function returns the integer square root of n, meaning the biggest integer whose square is less than or equal to n. You may
assume that the function is always called with a nonnegative value for n.
Use the following algorithm:
If n is 0 then return 0.
Otherwise, call the function recursively with n-1 as the argument to get a number t. Check whether or not t+1 squared is strictly
greater than n. Based on that test, return the correct result.
For example, a call to simpleSqrt(8) would recursively call simpleSqrt(7) and get back 2 as the answer. Then we would square (2+1)
= 3 to get 9. Since 9 is bigger than 8, we know that 3 is too big, so return 2 in this case.
On the other hand a call to simpleSqrt(9) would recursively call simpleSqrt(8) and get back 2 as the answer. Again we would square
(2+1) = 3 to get back 9. So 3 is the correct return value in this case.
CodeW
For fun X C Solved
https://codeworkou...
臺亂
CodeWorkout
X272: Recursion Programming Exercise: Is
Reverse
For function isReverse, write the two missing base case conditions. Given two strings, this
function returns true if the two strings are identical, but are in reverse order. Otherwise it
returns false. For example, if the inputs are "tac" and "cat", then the function should return true.
Examples:
isReverse("tac", "cat") -> true
Your Answer:
1 public boolean isReverse(String s1, String s2) {
2.
if >
3.
4.
else if >
return true;
return false;
5.
6.
else {
String s1first =
String s2last
return s1first.equals (s2last) &&
51. substring(0, 1);
s2, substring(s2.length() 1);
7.
8.
6.
isReverse(s1.substring(1), s2.substring(0, s2.length() 1));
{
12}
1:11AM
50°F Clear
12/4/2021
CodeW X
b For func x C Solved
X b Answer X
https://codeworkou...
CodeWorkout
X270: Recursion Programming Exercise:
Count Characters
For function countChr() write the missing part of the recursive call. This function should
return the number of times that the letter "A" appears in string "str".
Recall that str.substring(a) will return the substring of str from position a to the end of
str, while str.substring (a, b) will return the substring of str starting at position a and
continuing to (but not including) the character at position b.
Examples:
countChr ("ctcoWCAt") -> 1
Your AnsSwer:
1 public int countChr(String str) {
2.
if (str.length()
return 0;
} (0
4.
{
int count = 0;
www.
5.
9.
if (str.substring(0, 1).equals("A")) {
count = 1
7.
{
9.
return count + >
1:10 AM
50°F Clear
12/4/2021
呼
Chapter 14 Solutions
Problem Solving with C++ (9th Edition)
Ch. 14.1 - Prob. 1STECh. 14.1 - Prob. 2STECh. 14.1 - Prob. 3STECh. 14.1 - Prob. 4STECh. 14.1 - Prob. 5STECh. 14.1 - If your program produces an error message that...Ch. 14.1 - Write an iterative version of the function cheers...Ch. 14.1 - Write an iterative version of the function defined...Ch. 14.1 - Prob. 9STECh. 14.1 - Trace the recursive solution you made to Self-Test...
Ch. 14.1 - Trace the recursive solution you made to Self-Test...Ch. 14.2 - What is the output of the following program?...Ch. 14.2 - Prob. 13STECh. 14.2 - Redefine the function power so that it also works...Ch. 14.3 - Prob. 15STECh. 14.3 - Write an iterative version of the one-argument...Ch. 14 - Prob. 1PCh. 14 - Prob. 2PCh. 14 - Write a recursive version of the search function...Ch. 14 - Prob. 4PCh. 14 - Prob. 5PCh. 14 - The formula for computing the number of ways of...Ch. 14 - Write a recursive function that has an argument...Ch. 14 - Prob. 3PPCh. 14 - Prob. 4PPCh. 14 - Prob. 5PPCh. 14 - The game of Jump It consists of a board with n...Ch. 14 - Prob. 7PPCh. 14 - Prob. 8PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Open file P03-52. For the specified fault, predict the effect on the circuit. Then introduce the fault and veri...
Digital Fundamentals (11th Edition)
(IllegalTriangleException) Programming Exercise 11.1 defined the Triangle class with three sides. In a triangle...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
Describe a method that can be used to gather a piece of data such as the users age.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Write a loop equivalent to the for loop above without using .
C Programming Language
Write a function that dynamically allocates a block of memory and returns a char pointer to the block. The func...
Starting Out with C++ from Control Structures to Objects (8th Edition)
Knowledge Booster
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
- (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forwardCodeW X bFor fun X C Solved x b Answer + x https://codeworko... CodeWorkout X265: Recursion Programmlng Exercise: GCD The greatest common divisor (GCD) for a pair of numbers is the largest positive integer that divides both numbers without remainder. For function GCD , write the missing base case condition and action. This function will compute the greatest common divisor of x and y.You can assume that x and y are both positive integers and that x > y. Greatest common divisor is computed as follows: = x and GCD(x, y) = GCD(y, x % y). Examples: GCD (6, 4) -> 2 Your An swer: 1 public int GCD(int x, int y) { if > { 2. > 3. } else { 4. return GCD(y, x % y); 9. { 7. 1:09 AM 50°F Clear 1V 1. 12/4/2021 甲arrow_forwardWrite a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, the pattern generated is as follows: **** *** ** * * ** *** **** Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the preceding pattern.arrow_forward
- Recursive ConversionConvert the following function to one that uses recursion.void sign(int n){while (n > 0)cout << "No Parking\n";n−−;}Demonstrate the function with a driver program.arrow_forward5. Given an integer n, you need to find the digital root of that integer using a recursive function. If n has only 1 digit, then its digital root is n. Otherwise, the digital root is equal to the digital root of the sum of the digits of n. The process continues until a single-digit number is reached. For example, digital_root of 576 is calculated as: digital_root (576) = 5+7+ 6 = 18 digital_root (18) = 1 +8=9 digital_root (9) = 9 Programming Language :- C So, the digital root of 576 is 9arrow_forwardRecursive Sum! Write a recursive function rc_sum(n:int) -> int that returns the sum of the first n positive integers. The function should look very similar to the factorial function you have seen before. Your Answer: 1 # Put your answer here 2 Submitarrow_forward
- Question 6 full explain this question very fast solution sent me Don't ignore any part all part work uarrow_forwardWrite a function that takes in an integer n and computes n!. Do this without recursion. In [ ]: deffactorial_iter(n):"""Takes in an integer n>0 and returns the product of all integers from 1 to n."""# YOUR CODE HEREraiseNotImplementedError() In [ ]: In [ ]: assert factorial_iter(6) == 720 assert factorial_iter(7) == 5040 assert factorial_iter(10) == 3628800arrow_forward8. Ackerman's Function Ackermann's Function is a recursive mathematical algorithm that can be used to test how well a system optimizes its performance of recursion. Design a function ackermann(m, n), which solves Ackermann's function. Use the following logic in your function: If m = 0 then return n + 1 If n = 0 then return ackermann(m-1,1) Otherwise, return ackermann(m-1,ackermann(m,n-1)) Once you've designed yyour function, test it by calling it with small values for m and n. Use Python.arrow_forward
- 2. Sum: a recursive function that computes the sum of integers 1, 2, 3, …., n for a given number n. So Sum(6) should return 1 + 2 + 3 + 4 + 5 + 6 , i.e. 21.sum(n) = n + sum(n-1)arrow_forwardThe following function f uses recursion:def f(n):if n <= 1return nelse return f(n-1) + f(n-2)Let n be a valid input, i.e., a natural number. Which of the following functions returns the same result but without recursion?a) def f(n):a <- 0b <- 1 if n = 0return aelsif n = 1 return belsefor i in 1..nc <- a + b a <- b b <- c return bb) def f(n):a <- 0i <- n while i > 0 a <- a + i + (i-1) return ac) def f(n): arr[0] <- 0 arr[1] <- 1 if n <= 1return arr[n]elsefor i in 2..n arr[i] <- arr[i-1] + arr[i-2]return arr[n]d) def f(n): arr[0..n] <- [0, ..., n] if n <= 1return arr[n]elsea <- 0 for i in 0..n a <- a + arr[i]return aarrow_forwardWrite recursive functions for the following equations:a. Harmonic number is defined by the equationb. Fibonacci numbers are defined by the formula:FN = FN-2 + FN-1, for N ≥ 2 with F0 = 0 and F1 = 1arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License