The iterative version was fine, pretty mechanical.
Start by clarifying the problem: greedy decoding selects the highest-probability next token at each step until the end token is reached. Then implement both recursive and iterative versions, ensuring the full sequence including the end token is returned. Finally, analyze time and space complexity, discussing trade-offs between recursion and iteration.
Pro tip: Mention that recursion depth could be an issue for long sequences, so iterative is often preferred in production; also note that greedy decoding is deterministic and may not be optimal for all tasks.
Confirm the input format (dictionary mapping tokens to continuations with probabilities), the start token, and the end token. Ask if probabilities are guaranteed to sum to 1 and if there are cycles.
At each step, select the continuation with the highest probability. Append it to the sequence and continue until the end token is selected. Ensure the end token is included in the output.
Write a recursive function that takes the current token and accumulated sequence. Base case: if current token is end token, return sequence. Otherwise, find the highest-probability next token and recurse.
Use a loop: start with the start token, repeatedly look up the highest-probability next token, append to sequence, and update current token until end token is reached. Return the sequence.
Time: O(n * m) where n is sequence length and m is average number of continuations per token (to find max). Space: O(n) for the sequence, plus O(n) recursion stack for recursive version.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
This is where I spent most of my time and honestly where things got messy.
Start by defining the problem and clarifying assumptions, then walk through the beam search algorithm step-by-step, covering edge cases and design decisions. Compare beam search with greedy decoding on quality, complexity, and use cases, and illustrate with a small example. Conclude with trade-offs and potential optimizations.
Pro tip: Emphasize that beam search is a heuristic and discuss how beam width and length normalization affect the quality-diversity trade-off, showing awareness of practical tuning.
Restate the problem, define inputs/outputs, and state assumptions about the model (e.g., provides log-probabilities, vocabulary, end-of-sequence token).
Explain BFS-style expansion: maintain top-k sequences by cumulative log-probability, expand each with all possible next tokens, prune to top-k, and repeat until termination.
Discuss handling ties (e.g., stable sort, random tie-breaking), missing tokens (e.g., unknown token handling), cycles/dead-ends (e.g., avoid infinite loops, handle EOS), score normalization (e.g., length normalization), and termination conditions (e.g., max length, EOS).
Contrast quality (beam search finds higher-probability sequences), complexity (beam search O(k * V) per step vs greedy O(V)), and use cases (beam search for translation/summarization, greedy for real-time/low-resource).
Walk through a tiny vocabulary and model to show how beam search with k=2 expands and selects sequences, highlighting differences from greedy.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.