PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Other

Prove reservoir sampling correctness

Last updated: Mar 29, 2026

Quick Overview

This question evaluates randomized and streaming algorithm skills, including mastery of reservoir sampling, induction-based correctness proofs, probability reasoning, and complexity analysis for sampling under strict memory constraints.

  • Medium
  • Other
  • Coding & Algorithms
  • Data Scientist

Prove reservoir sampling correctness

Company: Other

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Design an algorithm to sample k items uniformly at random from a stream of unknown and potentially massive length N, using O(k) memory and one pass. (a) Write the algorithm for k=1 and generalize to k>1. (b) Prove by induction that after processing i items, each seen item has probability k/i to be in the reservoir. (c) Discuss time and memory complexity, and outline how you would adapt it for weighted sampling.

Quick Answer: This question evaluates randomized and streaming algorithm skills, including mastery of reservoir sampling, induction-based correctness proofs, probability reasoning, and complexity analysis for sampling under strict memory constraints.

Related Interview Questions

  • Implement a multi-button click detector - Other (hard)
  • Compute total after discounting most expensive item - Other (medium)
  • Return the k-th row of Pascal-like triangle - Other (medium)
  • Implement multiplication without using the multiplication operator - Other (Medium)
  • Write mini-batch gradient descent - Other (Medium)
Other logo
Other
Oct 13, 2025, 9:49 PM
Data Scientist
Onsite
Coding & Algorithms
2
0

Design an algorithm to sample k items uniformly at random from a stream of unknown and potentially massive length N, using O(k) memory and one pass. (a) Write the algorithm for k=1 and generalize to k>1. (b) Prove by induction that after processing i items, each seen item has probability k/i to be in the reservoir. (c) Discuss time and memory complexity, and outline how you would adapt it for weighted sampling.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Other•More Data Scientist•Other Data Scientist•Other Coding & Algorithms•Data Scientist Coding & Algorithms
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.