Recursive Definition - Discrete Mathematics - Homework, Slides of Discrete Mathematics

During the study of discrete mathematics, I found this course very informative and applicable.The main points in these lecture slides are:Recursive Definition, Definition of Sequence, Recursive Algorithm, Efficient Implementation, Sum of Digits, Arithmetic Operators, Different Order of Elements, Direct from Definition, Iterative Algorithm

Typology: Slides

2012/2013

Uploaded on 04/27/2013

atmaja
atmaja 🇮🇳

4.2

(45)

181 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS173: Discrete Mathematical Structures
Spring 2006
Homework #7
Due 12/03/06
1. (6 points, 2 points each part)
Give a recursive definition of the sequence
{an},n= 1,2,3,K
if
a. an=2n+n
b. an=2n+(-2)n
c. an=n2+2n+1
2. (16 points, 4 points each part, 2 bonus points for efficient solution for (a))
a. Give a recursive algorithm for computing xy, where x and y are positive
integers. Efficient implementation will grant bonus points.
b. Describe a recursive algorithm to compute the sum of the digits of a
positive integer. You may only use arithmetic operators (such as floor and
remainder also known as div and mod) and not string operators (such as
“get the 5-th digit”) in your solution.
c. A partition of a positive integer n is a way to write n as a sum of positive
integers. For example, 7=3+2+1+1 is a partition of 7. Give a recursive
algorithm to find the number of partitions of a positive integer.
d. What is the number of recursive calls these functions make (both the one
you gave in (a) (b) and in (c)). Note that here we're asking you what's
3. (12 points, 4 points each part)
Consider the following recursive definition:
f(m,n)=
0 if m>=1 and n=0
2 if m>=1 and n=1
2n if m=0;
f(m-1,f(m,n-1)) if m>=1 and n>=2.
a. Show that f(1,n)= 2n for all n>=1.
b. Show that f(m,2)=4 for all m>=1.
Docsity.com
pf2

Partial preview of the text

Download Recursive Definition - Discrete Mathematics - Homework and more Slides Discrete Mathematics in PDF only on Docsity!

CS173: Discrete Mathematical Structures

Spring 2006

Homework

Due 12/03/

  1. (6 points, 2 points each part) Give a recursive definition of the sequence € { a (^) n } , n = 1 , 2 , 3 ,K (^) if a. an=2n+n b. an=2n+(-2)n c. an=n^2 +2n+
  2. (16 points, 4 points each part, 2 bonus points for efficient solution for (a)) a. Give a recursive algorithm for computing xy, where x and y are positive integers. Efficient implementation will grant bonus points. b. Describe a recursive algorithm to compute the sum of the digits of a positive integer. You may only use arithmetic operators (such as floor and remainder also known as div and mod ) and not string operators (such as “get the 5-th digit”) in your solution. c. A partition of a positive integer n is a way to write n as a sum of positive integers. For example, 7=3+2+1+1 is a partition of 7. Give a recursive algorithm to find the number of partitions of a positive integer. d. What is the number of recursive calls these functions make (both the one you gave in (a) (b) and in (c)). Note that here we're asking you what's
  3. (12 points, 4 points each part) Consider the following recursive definition: f(m,n)= 0 if m>=1 and n= 2 if m>=1 and n= 2n if m=0; f(m-1,f(m,n-1)) if m>=1 and n>=2. a. Show that f(1,n)= 2n^ for all n>=1. b. Show that f(m,2)=4 for all m>=1.

Docsity.com

c. Find f(3,3).

  1. (12 points) Suppose you have a function that accepts a music genre as input, and gives some song from that genre as output, f: GenresSongs. Denote dance music (a music genre) by D , and rock (another music genre) by R. A playlist is just a list of songs. For example, f(D)f(D) is a playlist of two dance songs. Give an inductive definition of a good playlist, P , which is defined to be a playlist that starts with a dance song and does not contain two consecutive rock songs. (You should assume that no song belongs to more than one genre.)
  2. (12 points, 4 points each part) a. Devise a recursive algorithm to find the n th term of the sequence defined by € a (^) 0 = (^1) , € a 1 = (^2) , € a 2 = (^3) , and € a (^) n = a (^) n - 1 + a (^) n - 2 + a (^) n - (^3) , for € n = 3 , 4 , 5 K (^). b. Devise an iterative algorithm to find the n th term of the sequence defined in part a. c. Is the algorithm from part a or the algorithm from part b more efficient? Explain.

Docsity.com