For this problem you must write the functions in a recursive manner (i.e. the function must call itself) – it is not acceptable to submit an iterative solution to these problems.
A. Complete the recursive function gcd(m, n) that calculate the greatest common denominator of two numbers with the following rules:
# If m = n, it returns n
# If m < n, it returns gcd(m, n-m)
# If m > n, it returns gcd(m-n, n) #
def gcd(m,n):
return None # Replace this with your implementation
B. Complete the following function that uses recursion to find and return the max (largest) value in the list u.
# find_max([1, 7, 4, 5] returns 7 # find_ max ([1, 7, 4, 5, 9, 2] returns 9 # def find_max(u):
return None # Replace this with your implementation
C. Complete the following recursive function that returns the zip of two lists u and v of the same length. Zipping the lists should place the first element from each into a new array, followed by the second elements, and so on (see example output).
# zip([1, 2, 3], [4, 5, 6]) returns [1, 4, 2, 5, 3, 6] # def zip(u, v):
return None # Replace this with your implementation
D. Complete the following recursive function that removes all occurrences of the number x from the list nums.
# remove_number(5, [1, 2, 3, 4, 5, 6, 5, 2, 1]) returns [1, 2, 3, 4, 6, 2, 1] # def remove_number(x, nums):
return None # Replace this with your implementation
E. Write a recursive function removeLetter(string, letter) that takes a string and a letter as input, and recursively removes all occurrences of that letter from the string. The function is case sensitive.
Some example test cases are below:
>>> removeLetter("test string", "t")
es sring
>>> removeLetter("mississipi", "i")
mssssp
>>> removeLetter("To be or not to be is a question.", "t")
To be or no o be is a quesion.
In PyCharm
In: Computer Science
Figure 8-31 shows a ball with mass m ? 0.341 kg attached to the end of a thin rod with length L ? 0.452 m and negligible mass. The other end of the rod is pivoted so that the ball can move in a vertical circle. The rod is held horizontally as shown and then given enough of a downward push to cause the ball to swing down and around and just reach the vertically up position, with zero speed there. How much work is done on the ball by the gravitational force from the initial point to (a) the lowest point, (b) the highest point, and (c) the point on the right level with the initial point? If the gravitational potential energy of the ball–Earth system is taken to be zero at the initial point, what is it when the ball reaches (d) the lowest point, (e) the highest point, and (f) the point on the right level with the initial point? (g) Suppose the rod were pushed harder so that the ball passed through the highest point with a nonzero speed. Would ?Ug from the lowest point to the highest point then be greater than, less than, or the same as it was when the ball stopped at the highest point?
In: Physics
The average number of customers at a window of a certain bank per minute during banking hours is four. Find the probability that during a given minute. i. No customers appear ii. Three or fewer customers
In: Statistics and Probability
A box contains 12 items of which 3 are defective. A sample of 3 items is selected from the box. Let X denotes the number of defective item in the sample. Find the probability distribution of X.
In: Statistics and Probability
Use the normal approximation to find the indicated probability.
The sample size is n, the population proportion of
successes is p, and X is the number of successes
in the sample.
n = 85, p = 0.64: P(X >
52)
In: Statistics and Probability
Finite Math
Four fair six sided dice are rolled. Given that at least two of the dice land on an odd number, what is the probability that the sum of the result of all four dice is equal to 14?
In: Statistics and Probability
A multiple-choice test consists of 22 questions with possible answers of a, b, c, d, e, f. Estimate the probability that with random guessing, the number of correct answers is at least 11. the answer is not 0.0016
In: Statistics and Probability
PROBLEM 1. There are 12 cards in a standard deck of cards with faces on them, namely the 4 Jacks, the 4 Queens, and the 4 Kings. Assume below that the deck is well shuffled.
(a). If you deal 5 cards without replacement, what is the probability of getting no face cards?
(b). If you deal 5 cards WITH replacement (each time replacing the previous card and shuffling before dealing the next card), what is the probability of getting no face cards?
REMARK: You should know which of (a) and (b) will have the larger answer even before doing the arithmetic.
(c). What is the expected number of face cards dealt in part (a)?
(d) What is the expected number of face cards dealt in part (b)?
In: Statistics and Probability
Suppose we have a single server in a shop and customers arrive in the shop with a Poisson arrival distribution at a mean rate of λ=0.5 customers per minute. The interarrival time have an exponential distribution with the average inter-arrival time being 2 minutes. The server has an exponential service time distribution with a mean service rate of 4 customers per minute. Calculate: 1. Overall system utilization 2. Number of customers in the system 3. Number of customers in the queue 4. Average time customers spend in the system 5. Average time customer spends in the queue 6. Probability all servers are busy 7. Probability an arriving customer has to wait
In: Statistics and Probability
State Farm Insurance studies show that in Colorado, 55% of the auto insurance claims submitted for property damage were submitted by males under 25 years of age. Suppose 9 property damage claims involving automobiles are selected at random.
(a) Let r be the number of claims made by males under age 25. Make a histogram for the r-distribution probabilities.
(b) What is the probability that four or more claims are made by
males under age 25? (Use 3 decimal places.)
(c) What is the expected number of claims made by males under age
25? What is the standard deviation of the r-probability
distribution? (Use 2 decimal places.)
| μ | |
| σ |
In: Statistics and Probability