0

I have a similar problem to link: coin change algorithm in scala using recursion

The Code is recursive and looks like:

def countChange(money: Int, coins: List[Int]): Int = {
    def count(capacity: Int, changes: List[Int]): Int = {
            if(capacity == 0) 1
            else if(capacity < 0) 0
            else if(changes.isEmpty && capacity >=1 )0
            else count(capacity, changes.tail) + count(capacity - changes.head, changes)
    }
count(money, coins)
}

My Questions is how to analyze the time complexity of this algorithm? Thanks!

Community
  • 1
  • 1
JASON
  • 7,371
  • 9
  • 27
  • 40

1 Answers1

0

This is form of tree recursion which grow exponentially with input. SICP has very nice explanation about this.

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Adi
  • 2,364
  • 1
  • 17
  • 23