<< Chapter < Page | Chapter >> Page > |
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:
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
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:
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.)
Notification Switch
Would you like to follow the 'Principles of object-oriented programming' conversation and receive update notifications?