<< Chapter < Page Chapter >> Page >
An overview of recursion and recursive algorithms from an object-oriented perspective.

Recursive data structures

A recursive data structure is an object or class that contains an abstraction of itself.

In mathematical terms, we say that the object is "isomorphic" to itself. The basic embodiment of a recursive data structure is the Composite Design pattern . Recursive data structures enable us to represent repetitive abstract patterns. In such, they enable us to generate or represent complexity from simplicity.

Characteristics of a recursive data structure:

  • Abstract representation : Since the actual total structure of the data is not known until run-time, the data must be represented by an abstraction, such as an abstract class or interface.
  • Base case(s) : These represent the "end" of the pattern. They are the termination point(s) of the data structure.
  • Inductive case(s) : These represent the on-going, "interior" portion of the repetitive pattern. They embody the ability to represent the data structure as a a simple connection between abstractly equivalent entities.

Recursive data structures are arguably the most important data structure in computer science as they are able to represent arbitrarily complex data. Indeed, if one looks across all the sciences, one sees that one of the fundamental modeling tools used is to attempt to

Recursive algorithms

In order to process a recursive data structure, it makes sense that any such algorithm should reflect the recursive nature of the data structure:

A recursive algorithm is a process that accomplishes its task, in part, by calling an abstraction of itself

Recursion is thus a special case of delegation.

In light of the above definition, it is not surprising that recursive algorithms and recursive data structures share common characteristics:

Characteristics of a recursive algorithm:

  • Abstract representation : Since the actual total process needed to process the recursive dataastructure of the data is not known until run-time, the algorithm must be represented by an abstraction, such as an abstract method (this is not the only way).
  • Base case(s) : These represent the "end" of the algorithm. They are the termination point(s) of the algorithm.
  • Inductive case(s) : These represent the on-going, "interior" portion of the algorithm. They embody the ability to process the recursive data structure by calling the same abstract process on the composed elements of the structure.

The similarity between recursive algorithms and recursive data structures is because in an OO system, the structure drives the algorithm . That is, it is the form of the data structure that determines the form if the algorithm. In an OO system, objects are asked to perform algorithms as they pertain to that object--that is, an algorithm on an object is a method of that object. The data has the behavior. The data is intelligent. This is in contrast to procedural or functional programming, where data is handed to the behavior. That is, stand-alone functions are used to process non-intelligent data. (Caveat: With all that said, in more advanced designs, we will show the algorithm can be decoupled from its data structure and thus be removed as a method of the data. This will not change the above principles however.)

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Principles of object-oriented programming. OpenStax CNX. May 10, 2013 Download for free at http://legacy.cnx.org/content/col10213/1.37
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Principles of object-oriented programming' conversation and receive update notifications?

Ask