Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 12, Problem 10MC
A recursive
a. solve the problem without recursion
b. reduce the problem to a smaller version of the original problem
c. acknowledge that an error has occurred and abort the
d. enlarge the problem to a larger version of the original problem
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:43
Students have asked these similar questions
Python question
Question 19 (Algorithmic problem)
Write a RECURSIVE function that, given a text (as a string), returns the same text with vowels replaced with a hyphen (-). See the examples given below (doctests)
Note: No marks will be awarded for non-recursive implementations.
def remove_vowels(text): """ Input: a string of text Output: the same text with vowels removed Examples: >>> remove_vowels('this text') 'th-s t-xt' >>> remove_vowels('Python') 'Pyth-n' >>> remove_vowels('') '' >>> remove_vowels('Apple') '-ppl-' >>> remove_vowels('myths') 'myths' """
6) Write a recursive function to calculate the summation of numbers from 1 to n. For exampleif the user enters 5, your program would add 1+2+3+4+5 and print out the answer 15.7) Write a recursive program to calculate Fibonacci numbers. Use the definition of a Fibonaccinumber where F(n) = F(n-1) + F(n-2).
use java to code
Write a program that implements a recursive algorithm that prints the factorial of the first 10 digits (1 to 10 and it is optional if you would like to include 0). The program must use a recursive algorithm and can be implemented in Java.
Chapter 12 Solutions
Starting Out with Python (3rd Edition)
Ch. 12.2 - It is said that a recursive algorithm has more...Ch. 12.2 - Prob. 2CPCh. 12.2 - What is a recursive case?Ch. 12.2 - What causes a recursive algorithm to stop calling...Ch. 12.2 - What is direct recursion? What is indirect...Ch. 12 - Prob. 1MCCh. 12 - A function is called once from a program's main...Ch. 12 - Prob. 3MCCh. 12 - Prob. 4MCCh. 12 - Prob. 5MC
Ch. 12 - Prob. 6MCCh. 12 - Any problem that can be solved recursively can...Ch. 12 - Actions taken by the computer when a function is...Ch. 12 - A recursive algorithm must _______ in the...Ch. 12 - A recursive algorithm must ______ in the base...Ch. 12 - An algorithm that uses a loop will usually run...Ch. 12 - Some problems can be solved through recursion...Ch. 12 - It is not necessary to have a base case in all...Ch. 12 - In the base case, a recursive method calls itself...Ch. 12 - In Program 12-2 , presented earlier in this...Ch. 12 - In this chapter, the rules given for calculating...Ch. 12 - Is recursion ever required to solve a problem?...Ch. 12 - When recursion is used to solve a problem, why...Ch. 12 - How is a problem usually reduced with a recursive...Ch. 12 - What will the following program display? def...Ch. 12 - Prob. 2AWCh. 12 - The following function uses a loop. Rewrite it as...Ch. 12 - Prob. 1PECh. 12 - Prob. 2PECh. 12 - Prob. 3PECh. 12 - Largest List Item Design a function that accepts a...Ch. 12 - Recursive List Sum Design a function that accepts...Ch. 12 - Prob. 6PECh. 12 - Prob. 7PECh. 12 - Ackermann's Function Ackermann's Function is a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Explain how database administration tasks vary with the size and complexity of the database.
Database Concepts (8th Edition)
(Game: craps) Craps is a popular dice game played in casinos. Write a program to play a variation of the game, ...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
What is an algorithm?
Starting Out With Visual Basic (8th Edition)
What is wrong with the following while statement? 1 while (z = 0) { 2 sum += z; 3 }
Java How To Program (Early Objects)
#inc1ude iostream #inc1ude string using namespace std; int main() { string s(5, 'a'); s.append(3, 'b'); s.inser...
Starting Out with C++: Early Objects
Repair Bill Suppose automobile repair customers are billed at the rate of per hour for labor. Also, suppose co...
Introduction To Programming Using Visual Basic (11th 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
- 1.)I have to recursive with python language and was asked to do a buy 2 get 1 free where you have some amount of money(x) each item costs a given amount(y), for each 2 item you get 1 free, builda recursive solution to find out how many items you can buy for x amount of money. 2.) Buy M, get N free Then alter your first answer to allow for the user to enter any M and N for how many you need to buy to get free itemsarrow_forwardThe triangle.cpp ProgramDoes recursion actually work? If you run the triangle.cpp program, you’ll see that itdoes. The program uses recursion to calculate triangular numbers. Enter a value for the term number, n, and the program will display the value of the corresponding triangular number. show the triangle.cpp programarrow_forwardWrite a java recursive program to solve the "Missionaries and Cannibals" problem:Three missionaries and three cannibals come to a river and find a boat that holds two. If the cannibals ever outnumber the missionaries on either bank, the missionaries will be eaten. How might they cross safely? Input a character from the keyboard either a c (cannibal) or m (missionary). Check case and error check inputs. The output should include the initial problem, the moves you make, and a "picture" of the current state of the puzzle after each move (round). The final output should include the total number of rounds needed to solve the problem. Finally, ask the user if they wish to run the program again. The program must use recursion as part of the solution. Refer to the sample output below. Sample Run (partial):Crossing the River-----------------------------------------Round 0Left RightMMMCCCBoatFirst passenger (c for cannibal, m for missionary): HIllegal Input!First passenger (c for cannibal, m for…arrow_forward
- Implement the The triangle.cpp Program.This program uses recursion to calculate triangular numbers. Enter a value for the term number, n, and the program will display the value of the corresponding triangular number.arrow_forward1. Write a recursive function that returns the nth Fibonacci number from the Fibonacci series. int fib(int n); 2. Write a recursive function to find the factorial of a number. int factorial(int n); 3. Write a recursive function that returns the sum of the digits of an integer. int sumOfDigits(int x); 4. Write a recursive function that find the minimum element in an array of integers. int findMin(int a[], int size); 5. Write a recursive function that converts a decimal number to binary number. int DecToBin(int dec); 6. Write a recursive function that find the sum of the following series. 1 + 1/2 + 1/4 + 1/8 + ... + 1/2narrow_forwardProblem solving using recursion There are two skeleton programs, flesh them out following the suggestions given. Recursive algorithm for calculating xn (n ≥0): if n = 0, return 1.0 else return x * xn-1 (slow technique)Alternate (faster) algorithm: if n = 0, return 1.0 else if n is odd return x * xn-1 else { y = xn/2; return y * y;} (fast technique). Run program with several input values and compare results from fast power, slow power, and Math.pow in this table:Show all digits displayed by your program. You could add a loop to your program and paste the screen shot for all input values mentioned here instead. Show all digits. Base Exponent slow power fast power Math.pow3.5 64 5 15 1.25 31 2 17 String matchingFinding needle in a haystack:If needle is longer than the haystack then failureelse if needle matches the initial portion of haystack (use .startsWith() method) then successelse { create a…arrow_forward
- Problem solving using recursion There are two skeleton programs, flesh them out following the suggestions given. Recursive algorithm for calculating xn (n ≥0): if n = 0, return 1.0 else return x * xn-1 (slow technique)Alternate (faster) algorithm: if n = 0, return 1.0 else if n is odd return x * xn-1 else { y = xn/2; return y * y;} (fast technique). Run program with several input values and compare results from fast power, slow power, and Math.pow in this table:Show all digits displayed by your program. You could add a loop to your program and paste the screen shot for all input values mentioned here instead. Show all digits. Base Exponent slow power fast power Math.pow3.5 64 5 15 1.25 31 2 17 String matchingFinding needle in a haystack:If needle is longer than the haystack then failureelse if needle matches the initial portion of haystack (use .startsWith() method) then successelse { create a…arrow_forwardThe following problems below require the utilization of recursion to be solved. Must also have comments. 1. Write a python program that determine the greatest common divisor of two numbers. 2. Write a python program that computes the value of a number to a power 'n'.arrow_forwardInstructions : Complete the tasks listed below. ask Lists Complete the body for the recursive method fac(n) which computes n! (n factorial) for n >= 0. Note: n! = n(n - 1) (n - 2) (n - 2)… (2) (1), where n > 0 and zero factorial, 0! = 1. Complete the body for the recursive method sum(n) to compute the sum of the first n positive integers. Complete the body for the recursive method pow(x,n) for computing xn, for a positive integer n, and real number x. Complete the body for the recursive method isPalindrome(str) to determine if a string of text is a palindrome. This method accepts a String and returns true if the string reads the same forwards as backwards. The string is trivially true for empty or one(1) letter strings. Hint: You should make use of the subtring and charAt methods of the String. Run the Viewer of the Sierpinski Triangles and give a description of what you observed as it relates to recursion. Write a short summary (2-3 sentences is enough) of your…arrow_forward
- This is in Python This has two parts. This is a problem on recursion. Part a: Write a recursive function that accepts an integer argument, n. The user needs to be asked for the number n. The function should display n lines of asterisks on the screen, with the first (the top) showing 1 asterisk, the second from the top showing two asterisks, up to the nth line which shows n asterisks. Part b. Write a recursive function that accepts an integer argument, n. The user needs to be asked for the number n. The function should display n lines of asterisks on the screen, with the first (the top) showing n asterisks, the second from the top showing n-1 asterisks, up to the nth line which shows 1 asterisk. Submit the two files and two sample outputs for each of the parts.arrow_forwardThe following recursion occurs when there are more than two calls for each non-base case: : c)Multiple recursion d)Two Step Recursion a)Linear recursion b)Binary recursion Simple answer. Choose a or b or c or d.arrow_forwardQuestion) Which of the following is NOT a good strategy for designing recursive methods? A recursive method should include at least one conditional statement. A recursive method should establish a base case. A recursive method should reduce the problem to a smaller problem or problems and call itself recursively to solve the smaller problem(s). When the base case is reached stop the program and display results.arrow_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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License