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.

Google
Machine Learning
Data Scientist
Google
November 29, 2026
Data Scientist
Phone Screen
Machine Learning
Easy

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
NDCG
Graded relevance
Ranking metrics
Position discount
Search evaluation
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. 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 Prep
Sample Answer
Clarify

Confirm the label scale (say 0 to 3), the cutoff kk, 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

DCG@k=∑i=1k2reli−1log⁡2(i+1)DCG@k = \sum_{i=1}^{k} \frac{2^{rel_i}-1}{\log_2(i+1)} and NDCG@k=DCG@k/IDCG@kNDCG@k = DCG@k / IDCG@k, where IDCG is the DCG of the best possible ordering....


Submit Your Answer
Markdown supported