Home » Community » Forums » » Algorithmic Forays Part 7
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Algorithmic Forays Part 7
Post Reply 
I got it.
Thanks.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

As always, this is an excellent series of articles. However, I'd like to nitpick on the first paragraph of it:


0 is natural
n is natural => n+1 is natural


does not define natural numbers: it actually defines a variety of mathematical objects, inside which natural numbers as we know them are included. For instance, define alpha = beta + 1 and beta = alpha + 1, and it's impossible to prove alpha and beta aren't natural, while they aren't natural.

BlogFacebook

 User Rating: 1976   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

For fibonacci numbers x[n], if you take the matrix

1 1
1 0

And consider postmultiplying by the vector [ x[n], x[n-1] ] then you can see it works out [ x[n+1], x[n] ] applied recursively.

Simply diagonalise the matrix, and you have a general formula for fib numbers...

:)

 User Rating: 1015    Report this Post to a Moderator | Link

The count change problem can be implemented easier by using an iterative method using dynamic programming (related to memoization).


cache [ 0 ] = 1
(rest of cache is initialised to 0)

for all possible coins
loop from face_value to required_amount by step 1
cache [ loop_index_value ] += cache [ loop_index_value - face_value ]

When the algorithm terminates the number of ways to return change for a given value is found as cache [ required_amount ].
The algorithm runs in O(n*m), where n is number of distinct coins and m is the required amount to give change for, and it has memory consumption for the cache in O(m).

 User Rating: 1015    Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: