Skip to main content

Strings and Sequences

  • Chapter
  • First Online:
Explaining Algorithms Using Metaphors

Part of the book series: SpringerBriefs in Computer Science ((BRIEFSCOMPUTER))

  • 1513 Accesses

Abstract

In the last main chapter we deal with algorithms on strings and sequences. In the first section we consider two elementary data structures: the stack and the queue. We discuss the abundance of flawed metaphors used in education for the queue data structure, and propose better metaphors that should be used for this purpose. In the second section, we give our original exposition of the one-dimensional facility location problem and its solution. Our metaphor easily generalizes to more complicated variants of the problem. Finally, we present our original metaphor that illuminates the inner workings of the Knuth-Morris-Pratt substring search algorithm. This metaphor also leads to a clean implementation that easily avoids off-by-one errors (for which other implementations of KMP are well known).

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 54.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 69.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

Notes

  1. 1.

    Consider, e.g., http://www.dreamincode.net/forums/topic/273377-knuth-morris-pratt-algorit-hm%3B-reposted/ and http://pixelstech.net/article/1330941936_Overlap_Detection.

  2. 2.

    All these values \(S[i]\) are well-defined, because there is always a lemming at the beginning. The value \(S[0]\) is undefined, as there is no lemming to the left of that one.

References

  1. Aho, A.V., Corasick, M.J.: Efficient string matching: an aid to bibliographic search. Commun. ACM 18(6), 333–340 (1975)

    Article  MathSciNet  MATH  Google Scholar 

  2. Bajaj, C.: The algebraic degree of geometric optimization problems. Discrete Comput. Geom. 3, 177–191 (1988). doi:10.1007/BF02187906

    Article  MathSciNet  MATH  Google Scholar 

  3. Boyer, R.S., Moore, J.S.: A fast string searching algorithm. Commun. ACM 20(10), 762–772 (1977)

    Article  MATH  Google Scholar 

  4. Canny, J.F.: The Complexity of Robot Motion Planning. MIT Press (1988)

    Google Scholar 

  5. Chazelle, B.: Triangulating a simple polygon in linear time. Discrete Comput. Geom. 6(5), 485–524 (1991)

    Article  MathSciNet  MATH  Google Scholar 

  6. Chen, J., Han, Y.: Shortest paths on a polyhedron, part I: computing shortest paths. Int. J. Comput. Geom. Appl. 6, 127–144 (1996)

    Article  MathSciNet  MATH  Google Scholar 

  7. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 3rd edn. MIT Press (2009)

    Google Scholar 

  8. Hassin, R., Tamir, A.: Improved complexity bounds for location problems on the real line. Oper. Res. Lett. 10, 395–402 (1991)

    Article  MathSciNet  MATH  Google Scholar 

  9. Kariv, O., Hakimi, S.L.: An algorithmic approach to network location problems, Part II: \(p\)-medians. SIAM J. Appl. Math. 37, 539–560 (1979)

    Article  MathSciNet  MATH  Google Scholar 

  10. Karp, R.M., Rabin, M.O.: Efficient randomized pattern-matching algorithms. IBM J. Res. Dev. 31(2), 249–260 (1987)

    Article  MathSciNet  MATH  Google Scholar 

  11. Keogh, J.E., Davidson, K.: Data Structures Demystified. McGraw-Hill (2004)

    Google Scholar 

  12. Knuth, D.E., James, H., Morris, J., Pratt, V.R.: Fast pattern matching in strings. SIAM J. Comput. 6(2), 323–350 (1977)

    Article  MathSciNet  MATH  Google Scholar 

  13. Manber, U., Myers, E.: Suffix arrays: a new method for on-line string searches. SIAM J. Comput. 22(5), 935–948 (1993)

    Article  MathSciNet  MATH  Google Scholar 

  14. Mirzaian, A.: Triangulating Simple Polygons: Pseudo-Triangulations. Tech. rep., York University (1988). Tech. report No. CS-88-12

    Google Scholar 

  15. Sedgewick, R., Wayne, K.: Algorithms, 4th edn. Addison-Wesley Professional (2011)

    Google Scholar 

  16. Tamir, A.: An \(O(pn^2)\) algorithm for the \(p\)-median and related problems on tree graphs. Oper. Res. Lett. 19, 59–64 (1996)

    Article  MathSciNet  MATH  Google Scholar 

  17. Ukkonen, E.: On-line construction of suffix trees. Algorithmica 14(3), 249–260 (1995)

    Article  MathSciNet  MATH  Google Scholar 

  18. Weiner, P.: Linear pattern matching algorithms. In: Proceedings of the 14th Annual Symposium on Switching and Automata Theory (SWAT 1973), pp. 1–11. IEEE Computer Society (1973)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Michal Forišek .

Rights and permissions

Reprints and permissions

Copyright information

© 2013 The Author(s)

About this chapter

Cite this chapter

Forišek, M., Steinová, M. (2013). Strings and Sequences. In: Explaining Algorithms Using Metaphors. SpringerBriefs in Computer Science. Springer, London. https://doi.org/10.1007/978-1-4471-5019-0_4

Download citation

  • DOI: https://doi.org/10.1007/978-1-4471-5019-0_4

  • Published:

  • Publisher Name: Springer, London

  • Print ISBN: 978-1-4471-5018-3

  • Online ISBN: 978-1-4471-5019-0

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics