Skip to main content

Recursion

  • Chapter
  • First Online:
The Python Workbook

Part of the book series: Texts in Computer Science ((TCS))

  • 12k Accesses

Abstract

A recursive function is a function that calls itself. Such functions normally include one or more base cases and one or more recursive cases. The base case is a version of the problem that has a known solution, or a solution that can be computed without using a smaller version of the same problem. When the base case for a recursive function executes the function’s result is computed without making a recursive call. In contrast, a recursive case uses one or more other versions of the same problem to compute its result. This results in one or more recursive calls when the program runs, typically to smaller or simpler versions of the problem. The recursive calls end when they reach the base case.

This chapter includes 14 exercise, all of which are well suited to being solved with one or more recursive functions. While some of the exercises involve only small recursive functions, others require recursion to be used together with a variety of Python language features that were introduced in previous chapters.

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

Access this chapter

Subscribe and save

Springer+ Basic
EUR 32.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or Ebook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

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 EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 54.99
Price excludes VAT (USA)
  • Durable hardcover 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.

    Only C, X and I are used in a subtractive manner. The numeral that a C, X or I precedes must have a value that is no more than 10 times the value being subtracted. As such, I can precede V or X, but it cannot precede L, C, D or M. This means, for example, that 99 must be represented by XCIX rather than by IC.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Ben Stephenson .

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Stephenson, B. (2019). Recursion. In: The Python Workbook. Texts in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-030-18873-3_8

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-18873-3_8

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-18872-6

  • Online ISBN: 978-3-030-18873-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics