SlideShare a Scribd company logo
1 of 16
Recursive Definitions &
Structural Induction:
Selected Exercises
Copyright © Peter Cappello 2
Exercise 10
Give a recursive definition of Sm( n ), the sum of
integer m + nonnegative integer n.
Copyright © Peter Cappello 3
Exercise 10 Solution
Give a recursive definition of Sm( n ), the sum of
integer m + nonnegative integer n.
Sm( n ) = ( n == 0 ) ? m : 1 + Sm( n – 1 );
Copyright © Peter Cappello 4
Exercise 20
Give a recursive definition of the functions max & min so that
max( a1, a2, …, an ) & min( a1, a2, …, an ) are the maximum &
minimum of a1, a2, …, an, respectively.
Copyright © Peter Cappello 5
Exercise 20 Solution
Give a recursive definition of the functions max & min so that
max( a1, a2, …, an ) & min( a1, a2, …, an ) are the maximum
& minimum of a1, a2, …, an, respectively.
max( a1 ) = a1;
max( a1, a2 ) = (a1  a2 ) ? a2 : a1; (Why is this needed?)
max( a1, a2, …, an ) = max (max( a1, a2, …, an-1 ) , an )
The min function is defined similarly.
Copyright © Peter Cappello 6
Exercise 30
Prove that in any bit string, the string 01 occurs at
most 1 more time than the string 10.
Copyright © Peter Cappello 7
Exercise 30
Prove that in any bit string “01” occurs at most 1 more time than the “10”.
• Can we prove it by induction?
• Can we base the induction on the length of the bit string?
• If we
– Show it’s true for | s | = 1
– Assume it’s true for | s | < n
• We try to show it’s true for | s | = n.
– We break the string into bit string r = the 1st n – 1 bits, followed by the last bit.
– Apply the induction hypothesis to r.
– Induction step: 4 cases, depending on the last bit of r & the last bit of s.
– The case fails when the last bit of r is 1 & the last bit of s is 0.
• What to do?
Copyright © Peter Cappello 8
Exercise 30 Proof
1. Basis: |s| = 1: #01(s) = 0  1 = #10(s) + 1
2. Assume: |s| < n  #01(s)  #10(s) + 1
3. Show: |s| = n  #01(s)  #10(s) + 1
(Decomposing s arbitrarily into 2 smaller strings, fails. Try it.)
Case: s does not contain substring “10”:
1. It is of the form 0*1*.
2. #01(s)  1 = #10(s) + 1.
Copyright © Peter Cappello 9
Case: s does contain substring “10”:
Break s into 2 strings, t and u, between a “10”
E.g., 100111011000 is broken into (100111)(011000 )
1. t ends in “1”; u begins with “0”.
2. #01(t)  #10(t) + 1 (S.I.H.)
3. #01(u)  #10(u) + 1 (S.I.H.)
4. #01(s) = #01(t) + #01(u)  #10(t) + #10(u) + 2 = #10(s) + 1.
Copyright © Peter Cappello 10
Exercise 40
To recursively define a set:
1. Define it to have some “initial” elements;
2. Give rules that compose new elements from pre-
existing elements.
Recursively define the set S of bit strings with more 0s
than 1s.
Copyright © Peter Cappello 11
Exercise 40 Solution
Recursively define the set S of bit strings that have more 0s than 1s.
1. 0  S.
2. x, y  S  xy, 1xy, x1y, xy1  S.
This recursive definition of set S is like a context free grammar.
S is a context-free language.
These grammars & languages are studied in CMPSC 138.
We use them to define the syntax of programming languages, like C, &
C++, Java, Python, Ruby, Scala, Haskell, etc.
1. 0  S.
2. x,y  S  xy, 1xy, x1y, xy1  S.
Elements of S have more 0s than 1s.
Proof by structural induction that x  S  x has more 0s than 1s.
Basis: 0  S has more 0s than 1s.
Assume: x,y  S have more 0s than 1s.
Show: xy, 1xy, x1y, xy1  S have more 0s than 1s.
#0(xy1) = #0(x) + #0(y)
≥ ( #1(x) + 1 ) + ( #1(y) + 1 )
= #1(xy1) + 1
> #1(xy1).
Copyright © Peter Cappello 12
Copyright © Peter Cappello 13
Exercise 50
Ackermann’s function is defined as follows:
A( m, n ) = 2n, if m = 0;
= 0, if m ≥ 1  n = 0
= 2, if m ≥ 1  n = 1
= A( m – 1, A( m, n – 1 ) ), if m ≥ 1  n ≥ 2.
Show that A( 1, k ) = 2k, for k ≥ 1.
Copyright © Peter Cappello 14
Exercise 50 Solution
Ackermann’s function is defined as follows:
A( m, n ) = 2n, if m = 0;
= 0, if m ≥ 1  n = 0
= 2, if m ≥ 1  n = 1
= A( m – 1, A( m, n – 1 ) ), if m ≥ 1  n ≥ 2.
Show that, for k ≥ 1, A( 1, k ) = 2k.
Basis k = 1: A( 1, 1 ) = 2 = 21.
Show A( 1, k ) = 2k  A( 1, k + 1 ) = 2k+1, for k ≥ 1.
Assume A( 1, k ) = 2k.
Prove A( 1, k + 1 ) = 2k+1:
A( 1, k + 1) = A( 0, A( 1, k ) ) = A( 0, 2k ) = 2 . 2k = 2k+1.
End
Copyright © Peter Cappello 2011 15
A Bijection between Z+ & Rooted
Trees
The discussion below is based on
Peter Cappello. A New Bijection between Natural Numbers and
Rooted Trees. 4th SIAM Conf. on Discrete Mathematics, San
Francisco, June 1988.
• Let P denote the set of prime numbers.
• Let T denote the set of rooted trees.
• Let p: Z+,  P, where p( n ) is the nth prime
(e.g., p( 4 ) = 7 and p-1( 7 ) = 4 ).
• p-1( n ) < n.
Copyright © Peter Cappello 16

More Related Content

Similar to 4.3e.pptx

SMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last versionSMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last versionLilyana Vankova
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpExcel Homework Help
 
Modeling with Recurrence Relations
Modeling with Recurrence RelationsModeling with Recurrence Relations
Modeling with Recurrence RelationsDevanshu Taneja
 
Dynamic1
Dynamic1Dynamic1
Dynamic1MyAlome
 
Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamicchidabdu
 
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog217-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2Shanmuganathan C
 
A PowerPoint presentation on sets
A PowerPoint presentation on setsA PowerPoint presentation on sets
A PowerPoint presentation on setsAyushChatterjee5
 
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurMid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurVivekananda Samiti
 
sublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiessublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiesFujimoto Keisuke
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab
 
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...Aladdinew
 
Free video lectures for mca
Free video lectures for mcaFree video lectures for mca
Free video lectures for mcaEdhole.com
 
Recursion Algorithms Derivation
Recursion Algorithms DerivationRecursion Algorithms Derivation
Recursion Algorithms DerivationRodrigue Tchamna
 

Similar to 4.3e.pptx (20)

SMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last versionSMB_2012_HR_VAN_ST-last version
SMB_2012_HR_VAN_ST-last version
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment Help
 
Imc2016 day1-solutions
Imc2016 day1-solutionsImc2016 day1-solutions
Imc2016 day1-solutions
 
Modeling with Recurrence Relations
Modeling with Recurrence RelationsModeling with Recurrence Relations
Modeling with Recurrence Relations
 
Dynamic1
Dynamic1Dynamic1
Dynamic1
 
Sienna 10 dynamic
Sienna 10 dynamicSienna 10 dynamic
Sienna 10 dynamic
 
6e-ch4.ppt
6e-ch4.ppt6e-ch4.ppt
6e-ch4.ppt
 
17-dynprog2.ppt
17-dynprog2.ppt17-dynprog2.ppt
17-dynprog2.ppt
 
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog217-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
17-dynprog2 17-dynprog2 17-dynprog2 17-dynprog2
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment Help
 
A PowerPoint presentation on sets
A PowerPoint presentation on setsA PowerPoint presentation on sets
A PowerPoint presentation on sets
 
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT KanpurMid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
Mid semexam | Theory of Computation | Akash Anand | MTH 401A | IIT Kanpur
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
sublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiessublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energies
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
 
Free video lectures for mca
Free video lectures for mcaFree video lectures for mca
Free video lectures for mca
 
Task 4
Task 4Task 4
Task 4
 
Recursion Algorithms Derivation
Recursion Algorithms DerivationRecursion Algorithms Derivation
Recursion Algorithms Derivation
 
Induction.pdf
Induction.pdfInduction.pdf
Induction.pdf
 

More from MuhammadAbubakar680442 (8)

pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Lecture 8 (1).pptx
Lecture 8 (1).pptxLecture 8 (1).pptx
Lecture 8 (1).pptx
 
Lecture 8.pptx
Lecture 8.pptxLecture 8.pptx
Lecture 8.pptx
 
verbs, regular irregular.pptx
verbs, regular irregular.pptxverbs, regular irregular.pptx
verbs, regular irregular.pptx
 
ONTO ONE TO ONE FUNCTION.ppt
ONTO ONE TO ONE FUNCTION.pptONTO ONE TO ONE FUNCTION.ppt
ONTO ONE TO ONE FUNCTION.ppt
 
Modal and Auxiliary Verbs.pptx
Modal and Auxiliary Verbs.pptxModal and Auxiliary Verbs.pptx
Modal and Auxiliary Verbs.pptx
 
Lecture 14.pptx
Lecture 14.pptxLecture 14.pptx
Lecture 14.pptx
 
onto into bijective.ppt
onto into bijective.pptonto into bijective.ppt
onto into bijective.ppt
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

4.3e.pptx

  • 1. Recursive Definitions & Structural Induction: Selected Exercises
  • 2. Copyright © Peter Cappello 2 Exercise 10 Give a recursive definition of Sm( n ), the sum of integer m + nonnegative integer n.
  • 3. Copyright © Peter Cappello 3 Exercise 10 Solution Give a recursive definition of Sm( n ), the sum of integer m + nonnegative integer n. Sm( n ) = ( n == 0 ) ? m : 1 + Sm( n – 1 );
  • 4. Copyright © Peter Cappello 4 Exercise 20 Give a recursive definition of the functions max & min so that max( a1, a2, …, an ) & min( a1, a2, …, an ) are the maximum & minimum of a1, a2, …, an, respectively.
  • 5. Copyright © Peter Cappello 5 Exercise 20 Solution Give a recursive definition of the functions max & min so that max( a1, a2, …, an ) & min( a1, a2, …, an ) are the maximum & minimum of a1, a2, …, an, respectively. max( a1 ) = a1; max( a1, a2 ) = (a1  a2 ) ? a2 : a1; (Why is this needed?) max( a1, a2, …, an ) = max (max( a1, a2, …, an-1 ) , an ) The min function is defined similarly.
  • 6. Copyright © Peter Cappello 6 Exercise 30 Prove that in any bit string, the string 01 occurs at most 1 more time than the string 10.
  • 7. Copyright © Peter Cappello 7 Exercise 30 Prove that in any bit string “01” occurs at most 1 more time than the “10”. • Can we prove it by induction? • Can we base the induction on the length of the bit string? • If we – Show it’s true for | s | = 1 – Assume it’s true for | s | < n • We try to show it’s true for | s | = n. – We break the string into bit string r = the 1st n – 1 bits, followed by the last bit. – Apply the induction hypothesis to r. – Induction step: 4 cases, depending on the last bit of r & the last bit of s. – The case fails when the last bit of r is 1 & the last bit of s is 0. • What to do?
  • 8. Copyright © Peter Cappello 8 Exercise 30 Proof 1. Basis: |s| = 1: #01(s) = 0  1 = #10(s) + 1 2. Assume: |s| < n  #01(s)  #10(s) + 1 3. Show: |s| = n  #01(s)  #10(s) + 1 (Decomposing s arbitrarily into 2 smaller strings, fails. Try it.) Case: s does not contain substring “10”: 1. It is of the form 0*1*. 2. #01(s)  1 = #10(s) + 1.
  • 9. Copyright © Peter Cappello 9 Case: s does contain substring “10”: Break s into 2 strings, t and u, between a “10” E.g., 100111011000 is broken into (100111)(011000 ) 1. t ends in “1”; u begins with “0”. 2. #01(t)  #10(t) + 1 (S.I.H.) 3. #01(u)  #10(u) + 1 (S.I.H.) 4. #01(s) = #01(t) + #01(u)  #10(t) + #10(u) + 2 = #10(s) + 1.
  • 10. Copyright © Peter Cappello 10 Exercise 40 To recursively define a set: 1. Define it to have some “initial” elements; 2. Give rules that compose new elements from pre- existing elements. Recursively define the set S of bit strings with more 0s than 1s.
  • 11. Copyright © Peter Cappello 11 Exercise 40 Solution Recursively define the set S of bit strings that have more 0s than 1s. 1. 0  S. 2. x, y  S  xy, 1xy, x1y, xy1  S. This recursive definition of set S is like a context free grammar. S is a context-free language. These grammars & languages are studied in CMPSC 138. We use them to define the syntax of programming languages, like C, & C++, Java, Python, Ruby, Scala, Haskell, etc.
  • 12. 1. 0  S. 2. x,y  S  xy, 1xy, x1y, xy1  S. Elements of S have more 0s than 1s. Proof by structural induction that x  S  x has more 0s than 1s. Basis: 0  S has more 0s than 1s. Assume: x,y  S have more 0s than 1s. Show: xy, 1xy, x1y, xy1  S have more 0s than 1s. #0(xy1) = #0(x) + #0(y) ≥ ( #1(x) + 1 ) + ( #1(y) + 1 ) = #1(xy1) + 1 > #1(xy1). Copyright © Peter Cappello 12
  • 13. Copyright © Peter Cappello 13 Exercise 50 Ackermann’s function is defined as follows: A( m, n ) = 2n, if m = 0; = 0, if m ≥ 1  n = 0 = 2, if m ≥ 1  n = 1 = A( m – 1, A( m, n – 1 ) ), if m ≥ 1  n ≥ 2. Show that A( 1, k ) = 2k, for k ≥ 1.
  • 14. Copyright © Peter Cappello 14 Exercise 50 Solution Ackermann’s function is defined as follows: A( m, n ) = 2n, if m = 0; = 0, if m ≥ 1  n = 0 = 2, if m ≥ 1  n = 1 = A( m – 1, A( m, n – 1 ) ), if m ≥ 1  n ≥ 2. Show that, for k ≥ 1, A( 1, k ) = 2k. Basis k = 1: A( 1, 1 ) = 2 = 21. Show A( 1, k ) = 2k  A( 1, k + 1 ) = 2k+1, for k ≥ 1. Assume A( 1, k ) = 2k. Prove A( 1, k + 1 ) = 2k+1: A( 1, k + 1) = A( 0, A( 1, k ) ) = A( 0, 2k ) = 2 . 2k = 2k+1.
  • 15. End Copyright © Peter Cappello 2011 15
  • 16. A Bijection between Z+ & Rooted Trees The discussion below is based on Peter Cappello. A New Bijection between Natural Numbers and Rooted Trees. 4th SIAM Conf. on Discrete Mathematics, San Francisco, June 1988. • Let P denote the set of prime numbers. • Let T denote the set of rooted trees. • Let p: Z+,  P, where p( n ) is the nth prime (e.g., p( 4 ) = 7 and p-1( 7 ) = 4 ). • p-1( n ) < n. Copyright © Peter Cappello 16