Compute NDCG at K for a Search Results Page by Hand
Last updated: November 29, 2026
Quick Overview
Given graded relevance labels for the top results a search ranker returned, compute NDCG@k, explain each part of the formula, and write a small function for it.
0
0
0 solved
Given graded relevance labels for the top results a search ranker returned, compute NDCG@k, explain each part of the formula, and write a small function for it.
Google Search quality work leans on graded human relevance ratings, and NDCG is a standard way to summarize them. The screener checks that you know the formula, why the discount is logarithmic, and how normalization makes queries comparable.
What the Interviewer Expects
- Define gain, discount, DCG and the ideal DCG
- Compute a small example correctly
- Explain why normalization lets you average across queries
- Explain why a log discount models attention falling with position
- Handle queries with no relevant results
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- Should the ideal ordering use only the returned results or all judged documents?
- Why use $2^{rel}-1$ instead of $rel$ as the gain?
- How would you compute NDCG when some results are unjudged?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Confirm the label scale (say 0 to 3), the cutoff , and whether the ideal ordering is built from the returned list or from every judged document for the query. The second is stricter because it pena...
Approach
and , where IDCG is the DCG of the best possible ordering....