Skip to main content Accessibility help
×
Hostname: page-component-76fb5796d-zzh7m Total loading time: 0 Render date: 2024-04-28T17:34:27.533Z Has data issue: false hasContentIssue false

9 - Efficiency

Published online by Cambridge University Press:  05 May 2013

Michael R. Hansen
Affiliation:
Technical University of Denmark, Lyngby
Hans Rischel
Affiliation:
Technical University of Denmark, Lyngby
Get access

Summary

The efficiency of a program is measured in terms of its memory requirements and its running time. In this chapter we shall introduce the concepts stack and heap because a basic understanding of these concepts is necessary in order to understand the memory management of the system, including the garbage collection.

Furthermore, we shall study techniques that in many cases can be used to improve the efficiency of a given function, where the idea is to search for a more general function, whose declaration has a certain form called iterative or tail recursive. Two techniques for deriving tail-recursive functions will be presented: One is based on using accumulating parameters and the other is based on the concept of a continuation, that represents the rest of the computation. The continuation-based technique is generally applicable. The technique using accumulating parameters applies in certain cases only, but when applicable it usually gives the best results. We give examples showing the usefulness of these programming techniques.

We relate the notion of iterative function to while loops and provide examples showing that tail-recursive programs are in fact running faster than the corresponding programs using while loops.

The techniques for deriving tail-recursive functions are useful programming techniques that often can be used to obtain performance gains. The techniques do not replace a conscious choice of good algorithms and data structures. For a systematic study of efficient algorithms, we refer to textbooks on “Algorithms and Data Structures.”

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2013

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Efficiency
  • Michael R. Hansen, Technical University of Denmark, Lyngby, Hans Rischel, Technical University of Denmark, Lyngby
  • Book: Functional Programming Using F#
  • Online publication: 05 May 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139093996.010
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Efficiency
  • Michael R. Hansen, Technical University of Denmark, Lyngby, Hans Rischel, Technical University of Denmark, Lyngby
  • Book: Functional Programming Using F#
  • Online publication: 05 May 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139093996.010
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Efficiency
  • Michael R. Hansen, Technical University of Denmark, Lyngby, Hans Rischel, Technical University of Denmark, Lyngby
  • Book: Functional Programming Using F#
  • Online publication: 05 May 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9781139093996.010
Available formats
×