Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved 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


imageimageimage

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Finite Mathematics and Its Applications

Authors: Larry J. Goldstein, David I. Schneider, Martha J. Siegel, Steven Hair

12th edition

978-0134768588, 9780134437767, 134768582, 134437764, 978-0134768632

More Books

Students also viewed these Programming questions

Question

identify the classifications of interventions;

Answered: 1 week ago