If I had a machine with multiple processors and trying to solve a huge problem, which algorithm would be best for solving this problem?
Dynamic Programming, Greedy or the Divide and Conquer algorithm?
If I had a machine with multiple processors and trying to solve a huge problem, which algorithm would be best for solving this problem?
Dynamic Programming, Greedy or the Divide and Conquer algorithm?
The Dynamic programming it use an array, which has to be synchronized between threads, which are searching for individual solutions.
The Greedy is kind of single threaded. Can be made multi threaded, but not a huge advantage imo. Anyway, you can use a pool of threads to shot with the best 5 matches...This would be the easiest to implement.
The Divide and Conquer is a recursive. If you would spawn a new thread still need a synchronization, but it can take the advantage clearly of multiple processor. I think it would be the second easier method to implement multithreaded.
The nature of the problem, which you need to solve it will decide which programming method should you use, not the processor core numbers.
Please take in considerations the time costs for switching the contexts between threads also!
This is an extremely broad question, and many things will depend on the specific problem you're trying to solve, but what you're looking for is whether an algorithm can run its steps in parallel. This can only be done if the result of one step does not depend on the result of another.
So generally, divide and conquer seems to be your best bet for running things in parallel.