the greedy method huffman' algorithm for building an optimal encoding is an example application of an algorithmic design pattern called the greedy method this design pattern is applied to optimization problemswhere we are trying to construct some structure while minimizing or maximizing some property of that structure the general formula for the greedy method pattern is almost as simple as that for the brute-force method in order to solve given optimization problem using the greedy methodwe proceed by sequence of choices the sequence starts from some well-understood starting conditionand computes the cost for that initial condition the pattern then asks that we iteratively make additional choices by identifying the decision that achieves the best cost improvement from all of the choices that are currently possible this approach does not always lead to an optimal solution but there are several problems that it does work forand such problems are said to possess the greedy-choice property this is the property that global optimal condition can be reached by series of locally optimal choices (that ischoices that are each the current best from among the possibilities available at the time)starting from well-defined starting condition the problem of computing an optimal variable-length prefix code is just one example of problem that possesses the greedy-choice property