I'm a begginer with C programming and I would need some help for a project. So...here it is what I have to do:
I have a non-void set M and a binary associative operation on M (say "*"). And I have to write a recursive function to determine the number of possibilities to evaluate the expression x1*x2*...*xn where xi is in M.
Evaluate would mean for example for 3 numbers: (x1*x2)*x3 and x1*(x2*x3). So two possibilities. I can't do (x1*x3)*x2, the terms have to be neighbours.
C programming...could someone please help me?
This problem is same as matrix chain multplication problem.
(M1 * M2) * M3 can be written as M1 * (M2 * M3), but can not be as (M1 * M3) * M2.
Such enumerating problems will be easily solved with dynamic programming optimal subproblem algorithms.
Many algorithmic books give solution to this problem.
Search for "matrix chain multiplicaton" on google.
If you want code than algorithm, approximate pseduocode is available at
http://www.cs.unm.edu/~saia/362-fall2004...
You have to translate that into c program though.
Reply:Check out http://www.pscode.com for great examples.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment