PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Machine Learning/Cresta

Design sequence decoding with greedy and beam search

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of sequence decoding algorithms, probabilistic next-token modeling, and algorithmic trade-offs between greedy and beam search for sequence generation.

  • medium
  • Cresta
  • Machine Learning
  • Software Engineer

Design sequence decoding with greedy and beam search

Company: Cresta

Role: Software Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Technical Screen

You are given a probabilistic next-token dictionary D that maps each token t to a dictionary of candidate next tokens {u: p(u|t)}. Use '<START>' as the start token and '.' as the end-of-sequence token. 1) Implement greedy decoding that, starting from '<START>', repeatedly selects the highest-probability next token until '.' is produced or no continuation exists. Provide both a recursive and an iterative version, and return the sequence of tokens (include '.' if produced). Analyze time and space complexity. 2) Implement beam search decoding with beam width k using a BFS-style expansion: at each decoding step, maintain up to k highest-scoring partial sequences ranked by cumulative log-probability, expand each by its top-k next tokens from D, and continue until all beams end with '.'. Return the best sequence and optionally the top-k sequences. Explain how you handle ties, tokens missing from D, potential cycles or dead-ends, score normalization (e.g., length normalization), and termination criteria. Compare greedy and beam search in terms of quality, complexity, and typical use cases, and demonstrate your implementations on a small example dictionary.

Quick Answer: This question evaluates understanding of sequence decoding algorithms, probabilistic next-token modeling, and algorithmic trade-offs between greedy and beam search for sequence generation.

Related Interview Questions

  • Implement greedy and beam decoding - Cresta (medium)
Cresta logo
Cresta
Aug 8, 2025, 12:00 AM
Software Engineer
Technical Screen
Machine Learning
56
0

Next-Token Decoding: Greedy and Beam Search

Context

You are given a probabilistic next-token dictionary D that maps each token t to a dictionary of candidate next tokens and their conditional probabilities: D[t] = {u: p(u | t)}. Use '<START>' as the start token and '.' as the end-of-sequence token. Assume probabilities in each D[t] sum to 1. If a token does not appear as a key in D, it has no continuations (dead-end).

Tasks

  1. Greedy Decoding
  • Starting from ' <START> ', repeatedly select the highest-probability next token until '.' is produced or no continuation exists.
  • Provide both a recursive and an iterative version.
  • Return the sequence of tokens after ' <START> ' (include '.' if produced).
  • Analyze time and space complexity.
  1. Beam Search Decoding (beam width k)
  • Use a BFS-style expansion: at each decoding step, maintain up to k highest-scoring partial sequences ranked by cumulative log-probability.
  • Expand each active beam by its top-k next tokens from D; continue until all beams end with '.'.
  • Return the best sequence and optionally the top-k sequences.
  • Explain how you handle:
    • Ties
    • Tokens missing from D (dead-ends)
    • Potential cycles
    • Score normalization (e.g., length normalization)
    • Termination criteria
  • Compare greedy vs. beam search in quality, complexity, and typical use cases.
  • Demonstrate your implementations on a small example dictionary.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Machine Learning•More Cresta•More Software Engineer•Cresta Software Engineer•Cresta Machine Learning•Software Engineer Machine Learning
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.