CHAPTER 6

image

Recursion

In this chapter, we will explain the following:

  • What a recursive definition is
  • How to write recursive functions in C
  • How to convert from decimal to binary
  • How to print a linked list in reverse order
  • How to solve Towers of Hanoi
  • How to write an efficient power function
  • How to sort using merge sort
  • What are static variables
  • How to use recursion to keep track of pending subproblems
  • How to implement backtracking using recursion by finding a path through a maze

6.1 Recursive Definition

A recursive definition is one that is defined in terms of itself. Perhaps the most common example is the factorial function. The factorial of ...

Get Advanced Topics in C: Core Concepts in Data Structures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.