Online Pen Testing

Authors Mingda Qiao , Gregory Valiant

Thumbnail PDF


  • Filesize: 0.83 MB
  • 26 pages

Document Identifiers

Author Details

Mingda Qiao
  • Stanford University, CA, USA
Gregory Valiant
  • Stanford University, CA, USA


We would like to thank Ian Tullis, Petr Mitrichev, and the entire problem setting team of Google Code Jam 2020 for writing and preparing the problem titled Pen Testing [Tullis and Mitrichev, 2020], which inspired this work. We thank the anonymous reviewers for their comments that have helped improve this paper.

Cite AsGet BibTex

Mingda Qiao and Gregory Valiant. Online Pen Testing. In 14th Innovations in Theoretical Computer Science Conference (ITCS 2023). Leibniz International Proceedings in Informatics (LIPIcs), Volume 251, pp. 91:1-91:26, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2023)


We study a "pen testing" problem, in which we are given n pens with unknown amounts of ink X₁, X₂, …, X_n, and we want to choose a pen with the maximum amount of remaining ink in it. The challenge is that we cannot access each X_i directly; we only get to write with the i-th pen until either a certain amount of ink is used, or the pen runs out of ink. In both cases, this testing reduces the remaining ink in the pen and thus the utility of selecting it. Despite this significant lack of information, we show that it is possible to approximately maximize our utility up to an O(log n) factor. Formally, we consider two different setups: the "prophet" setting, in which each X_i is independently drawn from some distribution 𝒟_i, and the "secretary" setting, in which (X_i)_{i=1}^n is a random permutation of arbitrary a₁, a₂, …, a_n. We derive the optimal competitive ratios in both settings up to constant factors. Our algorithms are surprisingly robust: (1) In the prophet setting, we only require one sample from each 𝒟_i, rather than a full description of the distribution; (2) In the secretary setting, the algorithm also succeeds under an arbitrary permutation, if an estimate of the maximum a_i is given. Our techniques include a non-trivial online sampling scheme from a sequence with an unknown length, as well as the construction of a hard, non-uniform distribution over permutations. Both might be of independent interest. We also highlight some immediate open problems and discuss several directions for future research.

Subject Classification

ACM Subject Classification
  • Theory of computation → Online algorithms
  • Optimal stopping
  • online algorithm


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Dorna Abdolazimi, Anna R Karlin, Nathan Klein, and Shayan Oveis Gharan. Matroid partition property and the secretary problem. arXiv preprint, 2021. URL:
  2. Susanne Albers and Leon Ladewig. New results for the k-secretary problem. Theoretical Computer Science, 863:102-119, 2021. Google Scholar
  3. Baruch Awerbuch, Yossi Azar, Amos Fiat, and Tom Leighton. Making commitments in the face of uncertainty: How to pick a winner almost every time. In Symposium on Theory of Computing (STOC), pages 519-530, 1996. Google Scholar
  4. Pablo D Azar, Robert Kleinberg, and S Matthew Weinberg. Prophet inequalities with limited information. In Symposium on Discrete Algorithms (SODA), pages 1358-1377, 2014. Google Scholar
  5. Moshe Babaioff, Michael Dinitz, Anupam Gupta, Nicole Immorlica, and Kunal Talwar. Secretary problems: weights and discounts. In Symposium on Discrete Algorithms (SODA), pages 1245-1254, 2009. Google Scholar
  6. Moshe Babaioff, Nicole Immorlica, David Kempe, and Robert Kleinberg. Matroid secretary problems. Journal of the ACM (JACM), 65(6):1-26, 2018. Google Scholar
  7. Moshe Babaioff, Nicole Immorlica, and Robert Kleinberg. Matroids, secretary problems, and online mechanisms. In Symposium on Discrete Algorithms (SODA), pages 434-443, 2007. Google Scholar
  8. R Bartoszyński and Z Govindarajulu. The secretary problem with interview cost. Sankhyā: The Indian Journal of Statistics, Series B, pages 11-28, 1978. Google Scholar
  9. Shant Boodaghians, Federico Fusco, Philip Lazos, and Stefano Leonardi. Pandora’s box problem with order constraints. In Conference on Economics and Computation (EC), pages 439-458, 2020. Google Scholar
  10. Sourav Chakraborty and Oded Lachish. Improved competitive ratio for the matroid secretary problem. In Symposium on Discrete Algorithms (SODA), pages 1702-1712, 2012. Google Scholar
  11. Shuchi Chawla, Evangelia Gergatsouli, Yifeng Teng, Christos Tzamos, and Ruimin Zhang. Pandora’s box with correlations: Learning and approximation. In Foundations of Computer Science (FOCS), pages 1214-1225. IEEE, 2020. Google Scholar
  12. José Correa, Paul Dütting, Felix Fischer, and Kevin Schewior. Prophet inequalities for iid random variables from an unknown distribution. In Conference on Economics and Computation (EC), pages 3-17, 2019. Google Scholar
  13. José Correa, Patricio Foncea, Ruben Hoeksma, Tim Oosterwijk, and Tjark Vredeveld. Posted price mechanisms for a random stream of customers. In Proceedings of the 2017 ACM Conference on Economics and Computation, pages 169-186, 2017. Google Scholar
  14. Michael Dinitz and Guy Kortsarz. Matroid secretary for regular and decomposable matroids. SIAM Journal on Computing, 43(5):1807-1830, 2014. Google Scholar
  15. Andrew Drucker. High-confidence predictions under adversarial uncertainty. Transactions on Computation Theory (TOCT), 5(3):1-18, 2013. Google Scholar
  16. Evgenii Borisovich Dynkin. The optimum choice of the instant for stopping a markov process. Soviet Mathematics, 4:627-629, 1963. Google Scholar
  17. Moran Feldman, Ola Svensson, and Rico Zenklusen. A simple o (log log (rank))-competitive algorithm for the matroid secretary problem. In Symposium on Discrete Algorithms (SODA), pages 1189-1201, 2014. Google Scholar
  18. Dimitris Fotakis, Dimitris Tsipras, Christos Tzamos, and Emmanouil Zampetakis. Efficient money burning in general domains. Theory of Computing Systems, 59(4):619-640, 2016. Google Scholar
  19. Anupam Gupta. Prophets and secretaries., 2017. Accessed: 2022-08-28.
  20. Anupam Gupta, Haotian Jiang, Ziv Scully, and Sahil Singla. The markovian price of information. In Integer Programming and Combinatorial Optimization (IPCO), pages 233-246, 2019. Google Scholar
  21. Friedrich Harten. Prophetenregionen bei zeitlichen Bewertungen im unabhängigen und im iid-Fall. PhD thesis, Gesellschaft zur Förderung der Mathematischen Statistik, 1996. Google Scholar
  22. Jason D Hartline and Tim Roughgarden. Optimal mechanism design and money burning. In Symposium on Theory of Computing (STOC), pages 75-84, 2008. Google Scholar
  23. Tony Huynh and Peter Nelson. The matroid secretary problem for minor-closed classes and random matroids. SIAM Journal on Discrete Mathematics, 34(1):163-176, 2020. Google Scholar
  24. Patrick Jaillet, José A Soto, and Rico Zenklusen. Advances on matroid secretary problems: Free order model and laminar case. In Integer Programming and Combinatorial Optimization (IPCO), pages 254-265, 2013. Google Scholar
  25. Martin Jones. Prophet inequalities for cost of observation stopping problems. Journal of Multivariate Analysis, 34(2):238-253, 1990. Google Scholar
  26. Robert Kleinberg. A multiple-choice secretary algorithm with applications to online auctions. In Symposium on Discrete Algorithms (SODA), pages 630-631, 2005. Google Scholar
  27. Holger Kösters. Difference prophet inequalities for [0, 1]-valued iid random variables with cost for observations. The Annals of Probability, 32(4):3324-3332, 2004. Google Scholar
  28. Ulrich Krengel and Louis Sucheston. On semiamarts, amarts, and processes with finite value. Probability on Banach spaces, 4:197-266, 1978. Google Scholar
  29. Oded Lachish. O (log log rank) competitive ratio for the matroid secretary problem. In Foundations of Computer Science (FOCS), pages 326-335, 2014. Google Scholar
  30. Tengyu Ma, Bo Tang, and Yajun Wang. The simulated greedy algorithm for several submodular matroid secretary problems. Theory of Computing Systems, 58(4):681-706, 2016. Google Scholar
  31. Aviad Rubinstein. Beyond matroids: Secretary problem and prophet inequality with general constraints. In Symposium on Theory of Computing (STOC), pages 324-332, 2016. Google Scholar
  32. Aviad Rubinstein and Sahil Singla. Combinatorial prophet inequalities. In Symposium on Discrete Algorithms (SODA), pages 1671-1687, 2017. Google Scholar
  33. Aviad Rubinstein, Jack Z Wang, and S Matthew Weinberg. Optimal single-choice prophet inequalities from samples. In Innovations in Theoretical Computer Science (ITCS), 2020. Google Scholar
  34. Ester Samuel-Cahn. A difference prophet inequality for bounded iid variables, with cost for observations. The Annals of Probability, pages 1222-1228, 1992. Google Scholar
  35. Sahil Singla. The price of information in combinatorial optimization. In Symposium on Discrete Algorithms (SODA), pages 2523-2532, 2018. Google Scholar
  36. José A Soto. Matroid secretary problem in the random-assignment model. SIAM Journal on Computing, 42(1):178-211, 2013. Google Scholar
  37. José A Soto, Abner Turkieltaub, and Victor Verdugo. Strong algorithms for the ordinal matroid secretary problem. Mathematics of Operations Research, 46(2):642-673, 2021. Google Scholar
  38. Ian Tullis and Petr Mitrichev. Pen testing., 2020. Accessed: 2022-08-28.
  39. Martin L Weitzman. Optimal search for the best alternative. Econometrica: Journal of the Econometric Society, pages 641-654, 1979. Google Scholar
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail