1 / 8

Practice Problem

Practice Problem. Themes Recursion Recurrence Definitions Recursive Relations Induction (prove properties of recursive programs and objects defined recursively ). Induction Examples. Prove: 1 + 3 + 5 + … + (2n-1) = n 2 4n < 2 n ,  n ≥ 5 2 n < n! ,  n ≥ 4. Tiling Dominoes.

Télécharger la présentation

Practice Problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Practice Problem • Themes • Recursion • Recurrence Definitions • Recursive Relations • Induction (prove properties of recursive programs and objects defined recursively)

  2. Induction Examples Prove: • 1 + 3 + 5 + … + (2n-1) = n2 • 4n < 2n ,  n ≥ 5 • 2n< n! ,  n ≥4

  3. Tiling Dominoes • Given a set of 1 × 2, how many different ways are there to tile and 2 × n rectangle placing a single domino vertically (2 × 1) or stacking two dominoes horizontally? • Example. For n = 3 there are 3 ways:

  4. Think Recursively • What are the base cases? • How do you solve the 2 × n using solutions to smaller problems?

  5. ACL Program to Count Dominoes • Derive a recurrence relation for D(n) the number of tilings of a 2 × n rectangle. • Write an ACL program, based on your recurrence, to compute D(n). • Produce a table of values of D(n) and compare to 2n and (3/2)n • Formulate a conjecture and use induction to prove your result.

  6. ACL Program • Derive a recurrence relation for D(n) the number of tilings of a 2 × n rectangle. • Write an ACL program, based on your recurrence, to compute D(n). • Produce a table of values of D(n) and compare to 2n and (3/2)n • Formulate a conjecture and use induction to prove your result.

  7. ACL Program to Generate Dominoes • Write a recursive ACL program (use programming mode) to generate all possible tilings of a 2 × n rectangle. • (defunGenDominoes (n) … ) • Represent tilings with “V” for one vertical tile and “HH” for two stacked horizontal tiles. • (concatenate ‘string “HH” “V”)  “HHV” • (length “HHV”)  3 • Return a list of strings, one for each possible tiling • Use auxiliary function mapconcat on next slide

  8. Auxiliary Function • Write a recursive function which concatenates a string s in front of all of the strings in a list L • (mapconcat s L) • (mapconcat “V” ‘(“HH” “VV”))  (“VHH” “VVV”)

More Related