RECURSION is squeezing my head this week...
I got the picture from:
http://darkfoxnewslog.blogspot.ca/
Clearly, I'm not the only one who is suffering from recursion. Luckily we won't be tested on writing recursion codes on Wednesday. I was holding that thought until seeing the last year test. I got wrong on the first question which was to trace a recursion.
Now I have concluded a standard thought to such question, take that question as an example:
Just trace s(1), s(2)...by pencil as carefully as you can!
s(1): (1, 1) since n == 1
s(2): min([2*s(1)[0] + 2*1 -1, 1]) == min([3, 1])
s(3): min([2*s[3-2][0] + 2*2-1, 2], [3, 1]) == min([5, 2], [3, 1])
and so on
Note: be careful of over-tracing



没有评论:
发表评论