06.03.2017 Views

Mathematics for Computer Science

e9ck2Ar

e9ck2Ar

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

“mcs” — 2017/3/3 — 11:21 — page 224 — #232<br />

224<br />

Chapter 7<br />

Recursive Data Types<br />

Figure 7.2<br />

Constructing the Koch Snowflake.<br />

Definition. Define the number # c .s/ of occurrences of the character c 2 A in the<br />

string s recursively on the definition of s 2 A :<br />

base case: # c ./ WWD 0.<br />

constructor case:<br />

(<br />

# c .s/ if a ¤ c;<br />

# c .ha; si/ WWD<br />

1 C # c .s/ if a D c:<br />

Prove by structural induction that <strong>for</strong> all s; t 2 A and c 2 A<br />

# c .s t/ D # c .s/ C # c .t/:<br />

Problem 7.10.<br />

Fractals are an example of mathematical objects that can be defined recursively.<br />

In this problem, we consider the Koch snowflake. Any Koch snowflake can be<br />

constructed by the following recursive definition.<br />

Base case: An equilateral triangle with a positive integer side length is a<br />

Koch snowflake.<br />

Constructor case: Let K be a Koch snowflake, and let l be a line segment<br />

on the snowflake. Remove the middle third of l, and replace it with two line<br />

segments of the same length jlj, as is done in Figure 7.2<br />

The resulting figure is also a Koch snowflake.<br />

Prove by structural induction that the area inside any Koch snowflake is of the<br />

<strong>for</strong>m q p 3, where q is a rational number.<br />

Problem 7.11.<br />

The set RBT of Red-Black Trees is defined recursively as follows:<br />

Base cases:<br />

hredi 2 RBT, and

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!