Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

A set of coins makes change for n if the sum of the values of the coins is n. For example, if you have 1-cent, 2-cent and 4-cent coins, the following sets make change for 7:

  • 7 1-cent coins
  • 5 1-cent, 1 2-cent coins
  • 3 1-cent, 2 2-cent coins
  • 3 1-cent, 1 4-cent coins
  • 1 1-cent, 3 2-cent coins
  • 1 1-cent, 1 2-cent, 1 4-cent coins

Thus, there are 6 ways to make change for 7. This function count_changetakes a positive integer n and a list of the coin denominations and returns the number of ways to make change for n using these coins (Hint: You will need to use tree recursion):

def count_change(amount, denominations):

  """Returns the number of ways to make change for amount.

 

  >>> denominations = [50, 25, 10, 5, 1]

  >>> count_change(7, denominations)

  2

  >>> count_change(100, denominations)

  292

  >>> denominations = [16, 8, 4, 2, 1]

  >>> count_change(7, denominations)

  6

  >>> count_change(10, denominations)

  14

  >>> count_change(20, denominations)

  60

  """

  "*** YOUR CODE HERE ***"  

  def count_using(min_coin, amount):

    if amount < 0:

      return 0

    elif amount == 0:

      return 1

    elif min_coin > amount:

      return 0

    else:

      with_min = count_using(min_coin, amount - min_coin)

      without_min = count_using(2*min_coin, amount)

      return with_min + without_min

  return count_using(1, amount)

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93124175
  • Price:- $10

Priced at Now at $10, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Uranium vi fluoride is crucial for the enrichment of

Uranium (VI) fluoride is crucial for the enrichment of weapons-grade uranium. If a 1.0 mol sample of helium effuses in 255 s, how many seconds will it take for the same amount of uranium (VI) fluoride to effuse under the ...

Aaninformationretrievalsystemhasacertainpairofaverageprecisi

(a) An information retrieval system has a certain pair of average precision and recall values when the system returns 10 documents in response queries. Would the precision and recall rate remain unchanged if the system w ...

How do you find the minimum sample size when population

How do you find the minimum sample size when population standard deviation is anywhere between 14 to 24, and the half-width B desired could be anywhere between 2 to 7?

Question what concerns should be understood about data

Question: What concerns should be understood about data communications being sent over wireless networks? Discuss the pros and cons of one method of transmission, such as Wireless Application Protocol. The response must ...

Two countries australia and france have their interest

Two Countries Australia and France have their interest rates to be 8% and 2 %, respectively. If their currencies trade according to 2 Australian $s buy one euro in the spot market, what will their future spot rate be in ...

Question find an article on the www that discusses a recent

Question: Find an article on the WWW that discusses a recent (within the last 2 years) security breach or Cyberattack. Provide a link to the article and suggest 2 Best practices for a user Domain Policy that would mitiga ...

Question how will you create the cicd process for this

Question: How will you create the CI/CD process for this application? Propose the tools, technologies required to achieve CI/CD in general. The response must be typed, single spaced, must be in times new roman font (size ...

Recently the discovery of a new data structure wonder heap

Recently, the discovery of a new data structure WONDER HEAP was announced. A WONDER HEAP has the same functionality and worst case behaviour as a binary heap except for DELETE MAX, which is implemented in O(log log n) (i ...

Systems analysis projectpersonal trainer inc owns and

Systems analysis project Personal Trainer, Inc. owns and operates fitness centers in a dozen Midwestern cities. The centers have done well, and the company is planning an international expansion by opening a new "superce ...

A confidence interval for a population mean is to be

A confidence interval for a population mean is to be estimated. The population standard deviation is guessed to be anywhere from 14 to 24. The half-width B desired could be anywhere from 2 to 7. Tabulate the minimum samp ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As