AI Glossary · Letter G

Greedy Algorithm.

An algorithm that makes the locally optimal choice at each decision step without considering how that choice affects future steps, trading the guarantee of a global optimum for computational speed. Greedy algorithms are embedded in many AI systems and optimization tools that agencies use, and understanding when greedy choices produce good solutions versus when they fail is important for evaluating and configuring these systems.

Also known as greedy search, greedy heuristic, greedy method

What it is

A working definition of the greedy algorithm.

A greedy algorithm solves a problem by making a sequence of choices, at each step selecting the option that looks best based on information available at that moment, without backtracking or reconsidering past choices based on what subsequent steps reveal. The name reflects this short-sighted optimization: the algorithm grabs the best-looking option greedily without planning ahead. For some problem structures, this local optimization strategy happens to produce the globally optimal solution; the classic example is Dijkstra’s algorithm for shortest paths, which is greedy but provably optimal on graphs with non-negative edge weights. For other problem structures, greedy choices lead to solutions that are far from optimal because the locally good choice forecloses a globally better path.

Greedy algorithms appear in AI systems across many levels of abstraction. In decision trees, the standard splitting criterion selects the feature and threshold that most reduces impurity at the current node, a greedy choice that does not consider whether a different split at this node would enable better splits at descendant nodes. In beam search, used for text generation in language models, the algorithm maintains a fixed number of candidate token sequences and extends each greedily, discarding sequences that fall below the top-k probability at each step. This is why language models sometimes produce suboptimal completions: the greedy beam search has committed to a path that looked good early but does not lead to the best overall sequence. In portfolio optimization and media allocation, greedy budget assignment adds spend to whichever channel shows the highest marginal return at each step, which may not produce the optimal overall allocation when channel interactions create non-additive returns.

The practical value of greedy algorithms is their speed. When a problem must be solved in real time, or when the solution space is so large that exhaustive search is computationally infeasible, a greedy approach produces a good-enough solution quickly. The engineering decision is whether the quality gap between the greedy solution and the optimal solution is acceptable for the application. For text generation with billions of tokens generated per day, the latency and compute cost of exact search would be prohibitive; greedy beam search produces acceptable quality at a fraction of the cost. For a one-time strategic media allocation decision, the computational cost of a more thorough search is justified by the value of the improvement.

Why ad agencies care

Why greedy algorithms matter more in agency work than in most industries.

Many of the AI tools and optimization systems a working ad agency uses daily are making greedy decisions under the hood. Understanding that these decisions are greedy, not globally optimal, informs how to evaluate their outputs, when to override them, and when the difference between greedy and optimal solutions is large enough to justify more expensive search methods.

Language model output quality depends partly on search strategy. When a language model produces a response that starts well but trails off awkwardly, or commits to a framing early in the response that prevents a better conclusion, the greedy beam search used for generation is often contributing. Temperature settings and nucleus sampling strategies modify the greediness of text generation, introducing more exploration at the cost of some coherence. Understanding this tradeoff helps agencies configure generation parameters for different use cases: high temperature for creative ideation tasks where diversity is valuable, lower temperature for factual or compliance-sensitive content where greedy precision matters more.

Budget pacing and allocation in ad platforms uses greedy rules. Most ad platform budget management systems allocate impressions and spend greedily based on current performance signals, without planning their spend trajectory to account for predicted future inventory availability, competitor behavior, or audience fatigue. This greedy pacing can exhaust budget in high-traffic periods and leave the campaign underdelivered in high-conversion-potential windows. Agencies that understand this can build pacing rules that constrain greedy spend in favor of more strategic budget management across the flight.

Feature selection and model building pipelines often use greedy forward selection. When building a predictive model with a large feature set, greedy forward feature selection adds the single feature that most improves model performance at each step, without reconsidering earlier additions. This can produce a feature set that is locally good but globally suboptimal if interactions between features make certain combinations far more powerful than the greedy sequential selection would discover. Understanding this limitation informs when to use more exhaustive feature search methods versus accepting the greedy result.

In practice

What greedy algorithm looks like inside a working ad agency.

An agency is generating social media copy variants for a consumer packaged goods client using a large language model with default generation settings. The client reviews the outputs and notes that many variants begin with strong hooks but conclude with generic calls to action that do not match the specific product benefit the copy is meant to highlight. The agency investigates the generation configuration and finds the model is using greedy decoding with a low temperature. They switch to nucleus sampling with a temperature of 0.8 and a top-p of 0.92, which introduces more exploration in the token selection process and reduces the model’s tendency to commit to predictable conclusion patterns after a strong opening. The revised generation settings produce copy where the conclusion is more specifically tied to the opening hook, because the less-greedy decoding strategy explores completion paths that the greedy approach would have pruned as lower-probability before their quality became apparent. Human review rates the revised outputs as meeting client brand standards 71% of the time without edits, up from 54% with greedy decoding.

Build the AI systems literacy that distinguishes greedy decisions from optimal ones and configures tools accordingly through The Creative Cadence Workshop.

The automations and agents module covers how AI tools make decisions during generation and optimization, including the search strategies that determine output quality and when to override default greedy configurations.