Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Structures.

Similar presentations


Presentation on theme: "Data Structures."— Presentation transcript:

1 Data Structures

2 Recursion Something is said to be recursive if each of the parts that make up the thing have a structure — in other words, a design or pattern — that repeats the structure of the whole thing itself. The fern shown here is recursive because each of its leaves has a structure like that of the entire fern itself.

3 Recursion The image shown here, a “Sierpinski gasket” is a recursive structure. It is generated by a recursive algorithm. A recursive algorithm is one that calls itself.

4 Here is an algorithm to draw a Sierpinski Gasket.
Sierpinski (triangle) Start Find the mid point of each side of the triangle Draw lines connecting the midpoints, which will form four smaller triangles that can be called triangles A, B, C, and D, with D in the center and the others around it. Color in (or cut out) the center triangle Do Sierpinski (triangle A) Do Sierpinski (triangle B) Do Sierpinski (triangle C) Stop Here is an algorithm to draw a Sierpinski Gasket. It splits a triangle into four smaller triangles, and then calls itself for three of the four smaller triangles. It is a recursive algorithm.

5 They are among the most powerful and useful of all algorithms.
Sierpinski (triangle) Start Find the mid point of each side of the triangle Draw lines connecting the midpoints, which will form four smaller triangles that can be called triangles A, B, C, and D, with D in the center and the others around it. Color in (or cut out) the center triangle Do Sierpinski (triangle A) Do Sierpinski (triangle B) Do Sierpinski (triangle C) Stop Recursive algorithms can generate complex structures from a simple instruction set. They are among the most powerful and useful of all algorithms.

6 Recursion Recursive algorithms can generate complex structures from a simple instruction set. They are among the most powerful and useful of all algorithms.


Download ppt "Data Structures."

Similar presentations


Ads by Google