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 9MC
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:35
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' """
Please help me with this using java and recursion. Please comment each of the code. amAs well as post an image of the program working
1) create a sierpenski triangle (Image 1)
2) create a sierpenski carpet (image 2)
Question-3
There are n number of students in a class.Assume a teacher enters and wants to shake hand according to an algorithm:
Algorithm (X) à 2n
a) Write a recursive function to solve this problem for any number of students also calculate the time complexity of your code, along with an idea what might be the best technique to solve this problem other than recursion.
b) Consider this Algorithm-Z , Taking list of integer as input
List Of Integer: X(Integer: number)
List Of Integer: Y
Integer: i = 2
While (i< number)
While (number Mod i == 0)
Y.Add(i)
number = number / i
End While
i = i + 1
End While
If (number > 1) Then Y.Add(number)
Return Y
End X
(i) Explain what Algorithm Z is doing?
(ii) Analyze the complexity of Algo-Z and then write an algorithm Better-Algo-X that does exactly the same thing but with a strictly better time complexity
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
Feetlnches Modification Modify the Feetlnches class discussed in this chapter so it overloads the following ope...
Starting Out with C++ from Control Structures to Objects (9th Edition)
You declare a named constant with which keyword? a. Constant b. Const c. NamedConstant d. Dim
Starting Out With Visual Basic (7th Edition)
Suppose the classes PartTimeEmployee and FullTimeEmployee inherited the properties of the class Employee. What ...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Write a program to print the corresponding Celsius to Fahrenheit table.
C Programming Language
TeamLeader Class In a particular factory, a team leader is an hourly paid production worker that leads a small ...
Starting Out with Java: Early Objects (6th 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
- Question-3 There are n number of students in a class. Assume a teacher enters and wants to shake hand according to an algorithm: Algorithm (X) à 2n a) Write a recursive function to solve this problem for any number of students also calculate the time complexity of your code, along with an idea what might be the best technique to solve this problem other than recursion. b) Consider this Algorithm-Z , Taking list of integer as input List Of Integer: X(Integer: number) List Of Integer: Y Integer: i = 2 While (i < number) While (number Mod i == 0) Y.Add(i) number = number / i End While i = i + 1 End While If (number > 1) Then Y.Add(number) Return Y End X (i) Explain what Algorithm Z is doing? (ii) Analyze the complexity of Algo-Z and then write an algorithm Better-Algo-X that does exactly the same thing but with a strictly better time complexityarrow_forwardThe following pattern of numbers is called Pascal’s triangle. The following pattern of numbers is called Pascal’s triangle. The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it. Write a procedure that computes elements of Pascal’s triangle by means of a recursive processarrow_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
- Question-3 There are n number of students in a class. Assume a teacher enters and wants to shake hand according to an algorithm: Algorithm (X) à 2n a) Write a recursive function to solve this problem for any number of students also calculate the time complexity of your code, along with an idea what might be the best technique to solve this problem other than recursion.arrow_forward1.)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_forwardIn this problem, you will write different programs to x^N, where x ∈ R, n ∈ N. b) Devise a recursive algorithm to compute x^n , using the fact that x^n= x ⋅ x^n−1 .arrow_forward
- Question) 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_forwardT/F 9. As loop variables and recursive solutions are also not used for iterative solutions, the recursive solution generally makes memorization more effective (use fewer stored) than the corresponding iterative solution.arrow_forwardRECURSION 3 Good day please help me with this practice exercise for our upcoming exam on last week of january.. I promise to give helpful rating after. Note: Please give the output of the program in the picture Please write your answer on a PAPER the tracing of the program in the picture. The answer should explain step by step on how I will get the output. Please refer to the second photo a sample tracing on how you would trace the first picture.. AGAIN 2ND PHOTO IS ONLY A SAMPLE ON HOW TO TRACE THE PROGRAM.arrow_forward
- Please help me create a sierpenski triangle using recursion. Please comment the code explaining each line of code. The program must be completed in java if you can please also create a t squared fractal using java and recursion (you don't have to comment the code)arrow_forwardConsider a network of streets laid out in a rectangular grid, In a northeast path from one point in the grid to another, one may walk only to the north (up) and to the east (right). Write a program that must use a recursive function to count the number of northeast paths from one point to another in a rectangular grid. Your program should prompt the user to input the numbers of points to the north and to east respectively, and then output the total number of paths. Notes: 1. Here is a file (timer.h download and timer.cpp download) which should be included in your program to measure time in Window or Unix (includes Mac OS and Linux) systems (use start() for the beginning of the algorithm, stop() for the ending, and show() for printing). 2. The computing times of this algorithm is very high, and the number of paths may be overflow, don't try input numbers even over 16. 3. Name your recursive function prototype as calcPath(int north, int east) to ease grading. 4. Paste your outputarrow_forwardWrite a recursive function to sort an array of integers into ascending order using the following idea: the function must place the smallest element in the first position, then sort the rest of the array by a recursive call. This is a recursive version of the selection sort. (Note: You will probably want to call an auxiliary function that finds the index of the smallest item in the array. Make sure that the sorting function itself is recursive. Any auxiliary function that you use may be either recursive or iterative.) Embed your sort function in a driver program to test it. Turn in the entire program and the output.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 LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
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