# 3.2 Recursion

 Page 1 / 2
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.)

state the properties of a base
state 3 properties of a base
State three properties of a base
mubarak
a stone is projected from the top of the tower 24.5m high with velocity of 39.2m/s at an angle of 30° with horizontal compute time taken to hit he ground
it took a car driver 30mins to travel a distance of 50km.what is the average speed
Suppose the master cylinder in a hydraulic system is at a greater height than the cylinder it is controlling. Explain how this will affect the force produced at the cylinder that is being controlled.
Why is popo less than atmospheric? Why is popo greater than pipi?
Louise
The old rubber boot shown below has two leaks. To what maximum height can the water squirt from Leak 1? How does the velocity of water emerging from Leak 2 differ from that of Leak 1? Explain your responses in terms of energy.
Louise
David rolled down the window on his car while driving on the freeway. An empty plastic bag on the floor promptly flew out the window. Explain why.
the pressure differential exerted a force on the bag greater than the gravitational force holding it on the floor.
gtitboi
what is angular velocity
The rate of change in angular displacement is defined as angular velocity.
Manorama
a length of copper wire was measured to be 50m with an uncertainty of 1cm, the thickness of the wire was measured to be 1mm with an uncertainty of 0.01mm, using a micrometer screw gauge, calculate the of copper wire used
Mustapha
it took a car driver 30 mins to travel a distance of 50km what is the average speed .
Isiguzo
If centripetal force is directed towards the center,why do you feel that you're thrown away from the center as a car goes around a curve? Explain
if there is a centripetal force it means that there's also a centripetal acceleration, getting back to your question, just imagine what happens if you pull out of a car when it's quickly moving or when you try to stop when you are running fast, anyway, we notice that there's always a certain force..
Lindomar
... that tends to fight for its previous direction when you try to attribute to it an opposite one ou try to stop it.The same thing also happens whe a car goes around a curve, the car it self is designed to a"straight line"(look at the position of its tyres, mainly the back side ones), so...
Lindomar
... whenever it goes around a curve, it tends to throw away its the occupiers, it's given to the fact that it must interrupt its initial direction and take a new one.
Lindomar
Which kind of wave does wind form
calculate the distance you will travel if you mantain an average speed of 10N m/s for 40 second
400m/s
Feng
hw to calculate the momentum of the 2000.0 elephant change hunter at a speed of 7.50 m/s
how many cm makes 1 inches
2.5
omwoyo
2.54cm=1inche
omwoyo
how do we convert from m/s to km/hr
When paddling a canoe upstream, it is wisest to travel as near to the shore as possible. When canoeing downstream, it may be best to stay near the middle. Explain why?
Explain why polarization does not occur in sound
one ship sailing east with a speed of 7.5m/s passes a certain point at 8am and a second ship sailing north at the same speed passed the same point at 9.30am at what distance are they closet together and what is the distance between them then
Got questions? Join the online conversation and get instant answers!