Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine cannonballs, and so forth. Given the following recursive function signature, write a recursive function that takes as its argument the height of a pyramid of cannonballs and returns the number of cannonballs it contains. Examples: cannonball (2) -> 5 Your Answer: 1 public int cannonball (int height) { 2345 Borot Feedback Your feedback will appear here when you check your answer. + uncc.instructure.com/courses/165385/assignments/1408115 08.06 Writing Practice Exercises X Me > | Applicant Login Pa... Robert Svoboda - A... > Login rapid proto Computer Network... S SOAP2DAY 8.6.2. Recursion Programming Exercise: Check Palindrome X275: Recursion Programming Exercise: Check Palindrome Write a recursive function named checkPalindrome that takes a string as input, and returns true if the string is a palindrome and false if it is not a palindrome. A string is a palindrome if it reads the same forwards or backwards. Recall that str.charAt(a) will return the character at position a in str. 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: checkPalindrome ("madam") -> true Your Answer: 1 public boolean checkPalindrome (String s) { Feedback Your feedback will appear here when you check your answer. 4 5 6 8 Check my answer! Reset 68F Mostly cloudy Q * = 7:41 PM 3/31/2022 8.6.3. Recursion Programming Exercise: Subset Sum X276: Recursion Programming Exercise: Subset Sum Write a recursive function that takes a start index, array of integers, and a target sum. Your goal is to find whether a subset of the array of integers adds up to the target sum. The start index is initially O. A target sum of O is true for any array. Examples: subsetSum(0, {2, 4, 8}, 10) -> true Your Answer: 1 public boolean subsetSum(int start, int[] nums, int target) { 3} 4 Check my answer! Reset Feedback Your feedback will appear here when you check your answer. 8.6.4. Recursion Programming Exercise: Pascal Triangle X277: Recursion Programming Exercise: Pascal Triangle Pascal's triangle is a useful recursive definition that tells us the coefficients in the expansion of the polynomial (x + a)^n. Each element in the triangle has a coordinate, given by the row it is on and its position in the row (which you could call a column). Every number in Pascals triangle is defined as the sum of the item above it and the item above it and to the left. If there is a position that does not have an entry, we treat it as if we had a 0 there. 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 Given the following recursive function signature, write the recursive function that takes a row and a column and finds the value at that position in the triangle. Assume that the triangle starts at row 0 and column 0. Examples: pascal (2, 1) -> 2 pascal (1, 2) -> 0 Your Answer: Feedback public int pascal(int row, int column) { Your feedback will appear here when you check your answer. Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine cannonballs, and so forth. Given the following recursive function signature, write a recursive function that takes as its argument the height of a pyramid of cannonballs and returns the number of cannonballs it contains. Examples: cannonball (2) -> 5 Your Answer: 1 public int cannonball (int height) { 2345 Borot Feedback Your feedback will appear here when you check your answer. + uncc.instructure.com/courses/165385/assignments/1408115 08.06 Writing Practice Exercises X Me > | Applicant Login Pa... Robert Svoboda - A... > Login rapid proto Computer Network... S SOAP2DAY 8.6.2. Recursion Programming Exercise: Check Palindrome X275: Recursion Programming Exercise: Check Palindrome Write a recursive function named checkPalindrome that takes a string as input, and returns true if the string is a palindrome and false if it is not a palindrome. A string is a palindrome if it reads the same forwards or backwards. Recall that str.charAt(a) will return the character at position a in str. 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: checkPalindrome ("madam") -> true Your Answer: 1 public boolean checkPalindrome (String s) { Feedback Your feedback will appear here when you check your answer. 4 5 6 8 Check my answer! Reset 68F Mostly cloudy Q * = 7:41 PM 3/31/2022 8.6.3. Recursion Programming Exercise: Subset Sum X276: Recursion Programming Exercise: Subset Sum Write a recursive function that takes a start index, array of integers, and a target sum. Your goal is to find whether a subset of the array of integers adds up to the target sum. The start index is initially O. A target sum of O is true for any array. Examples: subsetSum(0, {2, 4, 8}, 10) -> true Your Answer: 1 public boolean subsetSum(int start, int[] nums, int target) { 3} 4 Check my answer! Reset Feedback Your feedback will appear here when you check your answer. 8.6.4. Recursion Programming Exercise: Pascal Triangle X277: Recursion Programming Exercise: Pascal Triangle Pascal's triangle is a useful recursive definition that tells us the coefficients in the expansion of the polynomial (x + a)^n. Each element in the triangle has a coordinate, given by the row it is on and its position in the row (which you could call a column). Every number in Pascals triangle is defined as the sum of the item above it and the item above it and to the left. If there is a position that does not have an entry, we treat it as if we had a 0 there. 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 Given the following recursive function signature, write the recursive function that takes a row and a column and finds the value at that position in the triangle. Assume that the triangle starts at row 0 and column 0. Examples: pascal (2, 1) -> 2 pascal (1, 2) -> 0 Your Answer: Feedback public int pascal(int row, int column) { Your feedback will appear here when you check your answer.
Expert Answer:
Related Book For
Finite Mathematics and Its Applications
ISBN: 978-0134768632
12th edition
Authors: Larry J. Goldstein, David I. Schneider, Martha J. Siegel, Steven Hair
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
In what respects did certain employees regard the University of Baths culture under Breakwell as falling short of the aspirations described in the 2016-21 strategic plan?
-
Lucille receives an annual salary of $37,500 based on a 37.5-hour workweek. What are her gross earnings for a two-week pay period in which she works 9 hours of overtime at 1 times her regular rate...
-
The pre-closing trial balance for the Chance County Woodland Park Capital Projects Fund is provided on the next page. Required a. Prepare the June 30, 2017, statement of revenues, expenditures, and...
-
How is social media depriving protected classes of their civil rights?
-
You have been approached about doing a consulting job for Choi Hung Company, which is based in southern China. Choi Hung reports its financial results using International Financial Reporting...
-
Steven Cechetti and Kermit Schoenholz maintain a well-known blogMoney and Banking.Read theirposton Narrow Banking. Do they think narrow banking will work as suggested by Kotlikoff and others? What do...
-
FTMS Company currently has an income of 9.40 million dollars and this cash flow of the company no permanent growth. Company currently paying all earnings above as dividends. FTMS has a chance. The...
-
Larner Corporation is a diversified manufacturer of industrial goods. The company's activity - based costing system contains the following six activity cost pools and activity rates: Activity Cost...
-
Helix Corporation uses the weighted - average method in its process costing system. It produces prefabricated flooring in a series of steps carried out in production departments. All of the material...
-
Kingbird Company purchased Machine #201 on May 1, 2025. The following information relating to Machine #201 was gathered at the end of May. Price Credit terms Freight-in Preparation and installation...
-
Martha inadvertently failed to file her 2 0 2 3 tax return for eleven months. The tax due on the return was $ 1 , 750 . Her failure to file penalty will be ?
-
What ethical considerations arise in the development and communication of financial projections, and how are ethical guidelines and best practices applied to ensure the responsible use of projections...
-
Read the case study The Transformational Leadership of Ratan Tata 1. How did Ratan Tatas family background help him as he transformed Tata Group? How might it have presented obstacles or challenges...
-
ABC company leased new advanced computer equipment to STU Ltd on 1 January 2019.STULtd has to pay annual rental of $290,000 starting at 1 January 2019. It is a four years lease with ultimate rental...
-
How do children learn language?
-
Discuss the relationship between language and culture.
-
In the 1890 s, L. L. Zamenhof believed that different language was a key source of strife between people. He created Esperanto, which he hoped would be a universal language, to foster peace and...
Study smarter with the SolutionInn App