Presentation is loading. Please wait.

Presentation is loading. Please wait.

How would you define the following? 1. Jim is closer to the front of the line than Jane. 2. Class C1 is a descendant of class C2. 3. Your favorite airline.

Similar presentations


Presentation on theme: "How would you define the following? 1. Jim is closer to the front of the line than Jane. 2. Class C1 is a descendant of class C2. 3. Your favorite airline."— Presentation transcript:

1 How would you define the following? 1. Jim is closer to the front of the line than Jane. 2. Class C1 is a descendant of class C2. 3. Your favorite airline has the necessary flights to connect La Crosse to Dubuque. Frequently, a definition of one property (recursive or otherwise) relies upon knowledge of another, “simpler”, property. e.g.s: a > b may be defined in terms of closer to the front may be defined in terms of is a descendant of may be defined in terms of connect to (for an airline) may be defined in terms of One technique for defining such things is to use a recursive definition. Recursive definitions define property in terms of that same property (in a careful manner).

2 La Crosse Milwaukee Green Bay Madison Superior Eau Claire Dubuque Kenosha Oshkosh DEFINITION A connects to B Base A connects to B, if there is a Recursive A connects to B, if there is a direct flight between A & C and Extremal Under no other circumstances does A connect to B. The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

3 La Crosse Milwaukee Green Bay Madison Superior Eau Claire Dubuque Kenosha Oshkosh DEFINITION A connects to B Base A connects to B, if there is a direct flight between A & B. Recursive A connects to B, if there is a direct flight between A & C and C connects to B. Extremal Under no other circumstances does A connect to B. Use the definition to argue the following... La Crosse connects to Eau Claire. La Crosse connects to Green Bay. La Crosse connects to Dubuque. Notice that the recursive clause must be applied repeated times for many connections. The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

4 Base Clause... defines the property for a few (often one) simple cases. Recursive Clause... defines the property in terms of itself, but in such a way that repeated applications of the clause “make progress toward” the base. Extremal Clause... states that unless the property can be concluded via the base and recursive clauses the property is not true. (The extremal clause is typically omitted.) The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

5 DEFINITION jth Fibonacci number Base The 1 st Fibonacci number is 0. The 2 nd Fibonacci number is 1. Recursive If A n-1 is the (n-1) st Fibonacci number and A n-2 is the (n-2) nd Fibonacci, then is the nth Fibonacci. DEFINITION A greater than (>) B (HINT: Define > in terms of +1 and == ) DEFINITION A is an Odd Integer (HINT: Define odd in terms of +2 and == ) The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

6 Backus-Naur Form (BNF) is a notation developed around 1960 by John Backus and used by Peter Naur for expressive precise definitions of programming language syntax recursively. Notation denotes a nonterminal (Each nonterminal represents some set of possible character sequences.) ::= separates a nonterminal from its definition. (Informal translation:...is defined to be...) | separates alternative forms Each BNF defines a particular syntax by defining the syntax of each nonterminal in a separate rule of the form. ::= syntaxAlternatives The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

7 ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ::= | ::= 0 0 0 ::= | - | ( ) | + | - | * | / The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.


Download ppt "How would you define the following? 1. Jim is closer to the front of the line than Jane. 2. Class C1 is a descendant of class C2. 3. Your favorite airline."

Similar presentations


Ads by Google