Skip to main content

Functional Pearl: Nearest Shelters in Manhattan

  • Conference paper
Programming Languages and Systems (APLAS 2014)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 8858))

Included in the following conference series:

  • 916 Accesses

Abstract

Godzilla is attacking New York, and your task is to choose, for each shelter in the city, a nearest shelter to evacuate to. Luckily, distance between shelters is measured by Manhattan length, which allows us to complete the task in O(n logn) time. We present two algorithms: an algorithmic solution that solves the problem by a list-homomorphism, and a data structure based solution that exploits a “thinning” property.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Bentley, J.L.: Multidimensional divide-and-conquer. Communications of the ACM 23(4), 214–229 (1980)

    Article  MathSciNet  MATH  Google Scholar 

  2. Bird, R.S., de Moor, O.: Algebra of Programming. International Series in Computer Science. Prentice Hall (1997)

    Google Scholar 

  3. Chin, W.-N., Hu, Z.: Towards a modular program derivation via fusion and tupling. In: Batory, D., Blum, A., Taha, W. (eds.) GPCE 2002. LNCS, vol. 2487, pp. 140–155. Springer, Heidelberg (2002)

    Chapter  Google Scholar 

  4. Clarkson, K.L.: Fast algorithms for the all nearest neighbors problem. In: Synder, L. (ed.) Foundations of Computer Science, pp. 226–232. IEEE Computer Society Press (1983)

    Google Scholar 

  5. de Moor, O.: A generic program for sequential decision processes. In: Hermenegildo, M., Swierstra, S.D. (eds.) PLILP 1995. LNCS, vol. 982, pp. 1–23. Springer, Heidelberg (1995)

    Google Scholar 

  6. Gabow, H.N., Bentley, J.L., Tarjan, R.E.: Scaling and related techniques for geometry problems. In: DeMillo, R.A. (ed.) Theory of Computing, pp. 135–143. ACM Press (1984)

    Google Scholar 

  7. Gibbons, J.: The third homomorphism theorem. Journal of Functional Programming 6(4), 657–665 (1996)

    Article  MathSciNet  MATH  Google Scholar 

  8. Gries, D., Schneider, F.B.: A Logical Approach to Discrete Math. Springer (October 22, 1993)

    Google Scholar 

  9. Hu, Z., Iwasaki, H., Takeichi, M.: Construction of list homomorphisms via tupling and fusion. In: Penczek, W., Szałas, A. (eds.) MFCS 1996. LNCS, vol. 1113, pp. 407–418. Springer, Heidelberg (1996)

    Chapter  Google Scholar 

  10. Huet, G.: The zipper. Journal of Functional Programming 7(5), 549–554 (1997)

    Article  MathSciNet  MATH  Google Scholar 

  11. Morihata, A., Koishi, M., Ohori, A.: Dynamic programming via thinning and incrementalization. In: Codish, M., Sumii, E. (eds.) FLOPS 2014. LNCS, vol. 8475, pp. 186–202. Springer, Heidelberg (2014)

    Chapter  Google Scholar 

  12. Mu, S.-C., Lyu, Y.-H., Morihata, A.: Constructing datatype-generic fully polynomial-time approximation schemes using generalised thinning. In: Oliveira, B.C.d.S., Zalewski, M. (eds.) Workshop on Generic Programming, pp. 97–108. ACM Press (2010)

    Google Scholar 

  13. Sasano, I., Hu, Z., Takeichi, M., Ogawa, M.: Make it practical: A generic linear-time algorithm for solving maximum-weightsum problems. In: Odersky, M., Wadler, P. (eds.) International Conference on Functional Programming, pp. 137–149. ACM Press (2000)

    Google Scholar 

  14. Tarjan, R.E.: Amortized computational complexity. SIAM Journal on Algebraic and Discrete Methods 6(2), 306–318 (1985)

    Article  MathSciNet  MATH  Google Scholar 

  15. Vaidya, P.M.: An O(n logn) algorithm for the all-nearest-neighbors problem. Discrete and Computational Geometry 4(2), 101–115 (1989)

    Article  MathSciNet  MATH  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2014 Springer International Publishing Switzerland

About this paper

Cite this paper

Mu, SC., Chen, TW. (2014). Functional Pearl: Nearest Shelters in Manhattan. In: Garrigue, J. (eds) Programming Languages and Systems. APLAS 2014. Lecture Notes in Computer Science, vol 8858. Springer, Cham. https://doi.org/10.1007/978-3-319-12736-1_9

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-12736-1_9

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-12735-4

  • Online ISBN: 978-3-319-12736-1

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics