# Complexity of recursive calls

my brain is a little stuck as I am trying to compile an example for my blog. I am presenting an algorithm that draws a number from an array, adds it to a sum and calls itself recursively.

``````func solve(coins: Array<Int>, target: Int) -> Int {

func _solve(coins: Array<Int>, current: Int) -> Int {

var candidates = coins
var crt = current
while candidates.count > 0 {
// pop() removes the element at the head and returns it
let rdm: Int = candidates.pop()

if (current + rdm) > target {
continue
}

crt = _solve(candidates, current: current + rdm)

if crt == target {
return crt
}

}
return crt
}

return _solve(coins, current: 0)
}
``````

What this algorithm is doing is, given a set of coins, try to approach a given target as close as possible.

What is the complexity of this algorithm?

• What language is this? how is variable target visible to the inside function? – Degen Sharew Apr 5 '16 at 9:35
• It is Swift. I guessed it should be clear enough to be considered almost as pseudocode. – Mike M Apr 5 '16 at 10:13