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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Bentley, J.L.: Multidimensional divide-and-conquer. Communications of the ACM 23(4), 214–229 (1980)
Bird, R.S., de Moor, O.: Algebra of Programming. International Series in Computer Science. Prentice Hall (1997)
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)
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)
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)
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)
Gibbons, J.: The third homomorphism theorem. Journal of Functional Programming 6(4), 657–665 (1996)
Gries, D., Schneider, F.B.: A Logical Approach to Discrete Math. Springer (October 22, 1993)
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)
Huet, G.: The zipper. Journal of Functional Programming 7(5), 549–554 (1997)
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)
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)
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)
Tarjan, R.E.: Amortized computational complexity. SIAM Journal on Algebraic and Discrete Methods 6(2), 306–318 (1985)
Vaidya, P.M.: An O(n logn) algorithm for the all-nearest-neighbors problem. Discrete and Computational Geometry 4(2), 101–115 (1989)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)