10

Extending the question of streetparade, I would like to ask what is the difference, if any, between a stochastic and a heuristic algorithm.

Would it be right to say that a stochastic algorithm is actually one type of heuristic?

Community
  • 1
  • 1
orestis21
  • 203
  • 1
  • 2
  • 5

2 Answers2

10

TTBOMK, "stochastic algorithm" is not a standard term. "Randomized algorithm" is, however, and it's probably what is meant here.

Randomized: Uses randomness somehow. There are two flavours: Monte Carlo algorithms always finish in bounded time, but don't guarantee an optimal solution, while Las Vegas algorithms aren't necessarily guaranteed to finish in any finite time, but promise to find the optimal solution. (Usually they are also required to have a finite expected running time.) Examples of common Monte Carlo algorithms: MCMC, simulated annealing, and Miller-Rabin primality testing. Quicksort with randomized pivot choice is a Las Vegas algorithm that always finishes in finite time. An algorithm that does not use any randomness is deterministic.

Heuristic: Not guaranteed to find the correct answer. An algorithm that is not heuristic is exact.

Many heuristics are sensitive to "incidental" properties of the input that don't affect the true solution, such as the order items are considered in the First-Fit heuristic for the Bin Packing problem. In this case they can be thought of as Monte Carlo randomized algorithms: you can randomly permute the inputs and rerun them, always keeping the best answer you find. OTOH, other heuristics don't have this property -- e.g. the First-Fit-Decreasing heuristic is deterministic, since it always first sorts the items in decreasing size order.

If the set of possible outputs of a particular randomized algorithm is finite and contains the true answer, then running it long enough is "practically guaranteed" to eventually find it (in the sense that the probability of not finding it can be made arbitrarily small, but never 0). Note that it's not automatically the case that some permutation of the inputs to a heuristic will result in getting the exact answer -- in the case of First-Fit, it turns out that this is true, but this was only proven in 2009.

Sometimes stronger statements about convergence of randomized algorithms can be made: these are usually along the lines of "For any given small threshold d, after t steps we will be within d of the optimal solution with probability f(t, d)", with f(t, d) an increasing function of t and d.

j_random_hacker
  • 50,331
  • 10
  • 105
  • 169
  • 2
    You mention deterministic algorithms and this causes me additional confusion. Aren't a _deterministic_ and an _exact_ algorithm the same thing? – orestis21 Feb 05 '15 at 08:15
  • 3
    No, you can have deterministic heuristics. The First-Fit-Decreasing heuristic for bin packing is deterministic because given the same input, it will always produce the same output. But it's not exact, because it might not find the optimal solution. – j_random_hacker Feb 05 '15 at 14:20
  • 1
    this comment is quite enlightening. Can we then say that we have the dipoles _deterministic-stochastic_ and _exact-heuristics_? – orestis21 Feb 06 '15 at 09:19
  • Yes, you can -- and the 2nd and 3rd paragraphs in my answer say as much ;) – j_random_hacker Feb 06 '15 at 13:28
8

Booth approaches are usually used to speed up genere and test solutions to NP complete problems

  1. Stochastic algorithms use randomness

    They use all combinations but not in order but instead they use random ones from the whole range of possibilities hoping to hit the solution sooner. Implementation is fast easy and single iteration is also fast (constant time)

  2. Heuristics algorithms

    They pick up the combinations not randomly but based on some knowledge on used process, input dataset, or usage instead. So they lower the number of combinations significantly to only those they are probably the solution and use only those but usually all of them until solution is found.

    Implementation complexity depends on the problem, single iteration is usually much much slower then stochastic approach (constant time) so heuristics is used only if the number of possibilities is lowered enough to actual speed up is visible because even if algorithm complexity with heuristic is usually much lower sometimes the constant time is big enough to even slow things down ... (in runtime terms)

Booth approaches can be combined together

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • 1
    This answer is not entirely accurate. Neither of the two apply only to NP complete problems. See for example quicksort with randomized pivot selection, Welzl's algorithm, stochastic gradient descent etc. Heuristics are also not necessarily slower than randomization. – IVlad Jan 22 '15 at 10:06
  • @IVlad yep I know that but I never wrote they are only for such purpose ... but adding word `usually` will not hurt. the speed is about single iteration constant time (I never saw heuristic with smaller constant time then stochastic approach) – Spektre Jan 22 '15 at 10:09
  • @IVlad have reformulated the text a little. If you know a better reformulation feel free to edit my English skills are rusty – Spektre Jan 22 '15 at 10:19
  • Yes, NP-hardness has nothing to do with this question. – David Eisenstat Jan 22 '15 at 14:26