Advertisement

Functional Pearl: Nearest Shelters in Manhattan

  • Shin-Cheng Mu
  • Ting-Wei Chen
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8858)

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.

Keywords

Recursive Call Proof Obligation Manhattan Distance Binary Search Tree Input List 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Bentley, J.L.: Multidimensional divide-and-conquer. Communications of the ACM 23(4), 214–229 (1980)MathSciNetCrossRefzbMATHGoogle Scholar
  2. 2.
    Bird, R.S., de Moor, O.: Algebra of Programming. International Series in Computer Science. Prentice Hall (1997)Google Scholar
  3. 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)CrossRefGoogle Scholar
  4. 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. 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. 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. 7.
    Gibbons, J.: The third homomorphism theorem. Journal of Functional Programming 6(4), 657–665 (1996)MathSciNetCrossRefzbMATHGoogle Scholar
  8. 8.
    Gries, D., Schneider, F.B.: A Logical Approach to Discrete Math. Springer (October 22, 1993)Google Scholar
  9. 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)CrossRefGoogle Scholar
  10. 10.
    Huet, G.: The zipper. Journal of Functional Programming 7(5), 549–554 (1997)MathSciNetCrossRefzbMATHGoogle Scholar
  11. 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)CrossRefGoogle Scholar
  12. 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. 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. 14.
    Tarjan, R.E.: Amortized computational complexity. SIAM Journal on Algebraic and Discrete Methods 6(2), 306–318 (1985)MathSciNetCrossRefzbMATHGoogle Scholar
  15. 15.
    Vaidya, P.M.: An O(n logn) algorithm for the all-nearest-neighbors problem. Discrete and Computational Geometry 4(2), 101–115 (1989)MathSciNetCrossRefzbMATHGoogle Scholar

Copyright information

© Springer International Publishing Switzerland 2014

Authors and Affiliations

  • Shin-Cheng Mu
    • 1
  • Ting-Wei Chen
    • 2
  1. 1.Institute of Information ScienceAcademia SinicaTaipeiTaiwan
  2. 2.Dep. of Computer Science and Information EngineeringNational Taiwan UniversityTaipeiTaiwan

Personalised recommendations