comp sci
DESCRIPTION
discrete notesTRANSCRIPT
THE UNIVERSITY OF THE WEST INDIES
ASSIGNMENT 2 SEMESTER I, 2012/2013
Code and Name of Course: COMP2101/CS20S – Discrete Mathematics
Assignment 2 - Group Assignment
AREA
DESCRIPTION
Objectives To have students apply the knowledge garnered during weeks 5 to 10
To have students work within a group setting with the allocation of work but
still ensuring that the knowledge is spread throughout the group
Title Assignment 2 – Group Assignment
Deliverable The answers for the questions which follow the given instructions.
A summary of the contribution made by each student in the group.
Instructions 1. Review Lectures of weeks 5 to 10 of the course, the COMP2101 Text and
any other related Discrete Mathematics material
2. Read the Assignment 2 Sheet thoroughly
3. Submit the gradable solution by using the
COMP2101 Assignment 2 - Group located within the ASSIGNMENTS
Section of the OURVLE COMP2101/CS20S Course Environment. This
may also be accessed by choosing the Assignments section below
“Activities”
Format The solution for this assignment must be submitted as a Microsoft Word
document.
Your ID number should form part of the Microsoft Word file name. The file
name should take the format “COMP2101 Assignment 2 Semester 1 2012-
2013 XXXXXXXX YYYYYYYY ZZZZZZZZ” where XXXXXXXX, etc.
represents the student ID numbers.
Upload
Constraint
Assignment should be uploaded in the relevant space provided in
OURVLE (See “Instructions” section above). A message indicating “File
uploaded successfully” will acknowledge that the file has been sent
successfully.
Do NOT assume your project has been received if you do not get this
acknowledgement.
Group Restrictions
This is a group assignment. Each group must have a minimum of 2 members and a maximum of four (4) members.
Late
Assignments
Late assignments are accepted. These are however graded then 25%
deducted for each day of late submission.
Expectation It is expected that students will discuss means to a solution within their group.
The actual work written is expected to reflect the group’s decision. Where
replication of work is identified between groups, each paper will be graded.
The allocated grade to each group’s piece of work for where this anomaly is
identified will be the grade divided by the number of replications discovered.
Scoring Rubric
Your electronic submission will be evaluated on:
1. The response submitted for each question (See detail individual marks
below) – 45 marks
2. Group Dynamics i.e. for accomplishing the task as a group – 5 marks.
Marks allocated based on correct inclusion of each student id number and
name and a brief description as to the contribution made within the group.
The actual grade of 50 marks will be displayed. The actual grade allocated is
the percentage of the maximum marks (5 points)
Due Date
Monday, November 19, 2012
Question 1 [8 mks]
A coding system encodes messages using strings of octal digits (base 8). A codeword is
considered valid if and only if it contains an even number of 7s.
i. Find a recurrence relation for the number of valid codewords of length n.
State initial conditions. [4]
ii. Solve this recurrence relation using generating functions. [4]
Question 2 [2 mks]
a. Determine the limit of f(x) as x for the following:
33
5)(
x
xxf [1]
b. For the sequence a and b defined by
a1 = 2, an = 3an – 1, n ≥ 2, and bn = 2n (n – 1)
Find ))((7
3
5
2
j
j
i
i ba [1]
Question 3 [5 mks]
Find a formula for the sequence c defined by
n
i
in bc1
Where b is the sequence 1, 2, 4, 4, 7, 8, 10, … [5]
Question 4 [3 mks]
Let f(n) and g(n) be functions defined on the set of positive integers
Prove or disprove the following:
if f (n) = Ο (h(n)) and g(n) = Ο ( k(n))
then f(n)g(n) = Ο (h(n)k(n)). [3]
Question 5 [2 mks]
What is the limit of
n
k
k nasx0
? State all necessary
conditions for this limit to exist. [2]
Question 6 [7 mks]
Use generating functions to find a closed form solution for each of the following
recurrence relations:
i. a0 = 1 and an = 3an-1 + 2 for n ≥ 1 [3]
ii. s0 = 6, s1 = 5 and 9Sn = 6Sn-1 - Sn-2 for n ≥ 0 [4]
Question 7 [8 mks]
Let a,b,c be integers such that a ≥ 1, b > 1 and c > 0. Let f: N → R be functions
where N is the set of Natural numbers and R is the set of Real numbers
such that
f(1) = c and f(n) = af(n/b) + c
for n = bk, where k is a positive integer greater than 1.
(a) By using the principles of Recurrence Relation, find a general formula
for f(n) [4]
(b) Hence show that if a ≠ 1, then f(n) = )(1
)1( loglog
aa
b
b
na
anc
[4]
Question 8 [4 mks]
Consider the geometric series:
3 + 12/7 + 48/49 + 192/343 + …
i. Determine a formula for Sn
where Sn is the sum of the first n terms of the series? [3]
ii. What is the limit of Sn [1]
Question 9 [6 mks]
Find the generating function for the sequence
1, 4, 13, 28, 49, … [6]
Question 1 [8 mks]
A coding system encodes messages using strings of octal digits (base 8). A codeword is
considered valid if and only if it contains an even number of 7s.
i. Find a recurrence relation for the number of valid codewords of length n.
State initial conditions. [4]
ii. Solve this recurrence relation using generating functions. [4]
Solution 1
[i. Logical steps outlined towards finding general equation - 3 marks ]
[ Finding general equation f(n) or Sn - 1 mark ]
[ii. Correct initial layout of solution – 1st 3 statements - 1 mark ]
[ Application of Correct combining i.e. Subtraction - 1 mark ]
[ Logical steps towards correct solution - 2 marks ]
i.
Solution A - IF ZERO 7’S IS NOT CONSIDERED TO BE EVEN
Set of strings of 0, 1, 2, 3, 4, 5, 6, 7
Valid – String contains an even number of 7s e.g. 765703377112 or 001767 or 77
Let n be the length of the codeword
Sn be the number of valid codewords of length n or
Sn is the number of codewords of length n with an even number of 7s
i.e. Sn-1 is the number of codewords of length n-1 with an even number of 7s
Sn-2 is the number of codewords of length n-2 with an even number of 7s
etc.
By Counting
S0 = 0
S1 = 0
S2 = 1
S3 = 21
.
.
Firstly,
The valid codewords begins with a ‘7’ or Not
Let SA be the number of valid codewords of length n that Do Not begin with 7
SB be the number of valid codewords of length n that begins with 7
Then
Sn = SA + SB
Consider SA [Does Not Begin with ‘7’, i.e. begins with 0 or 1 or ... or 6]
Let us say a valid codeword that begins with 0
The other n-1 octal digits must contain an even number of 7s i.e. Sn-1
As there are 7 such cases
SA = 7Sn-1
Consider SB [Begins with ‘7’]
The other n-1 octal digits must contain an odd number of 7s
For these n-1 octal digits
The number of odds = Total number of codewords
minus The number of evens
minus The number without 7s (not odd or even)
Therefore,
As we are now considering the n-1 octal digits
SB = 8n-1
- Sn-1 - 7n-1
Therefore, As
Sn = SA + SB
The Recurrence Relation
Sn = 7Sn-1 + 8n-1
- Sn-1 - 7n-1
Simplified
Sn = 6Sn-1 + 8n-1
- 7n-1
for n > 1
For The Initial Conditions
When n = 1,
S1 = 0
S1 = 6S0 + 80 - 7
0
Therefore
S0 = 0
Solution B - IF ZERO 7’S IS CONSIDERED TO BE EVEN
Set of strings of 0, 1, 2, 3, 4, 5, 6, 7
Valid – String contains an even number of 7s e.g. 765703377112 or 001767 or 77
or 0123456065 or 333333 or 00 or 5
Let n be the length of the codeword
Sn be the number of valid codewords of length n or
Sn is the number of codewords of length n with an even number of 7s
i.e. Sn-1 is the number of codewords of length n-1 with an even number of 7s
Sn-2 is the number of codewords of length n-2 with an even number of 7s
etc.
By Counting
S1 = 7
S2 = 72 + 1 = 50
S3 = 73 + 3x7 = 364
.
.
Firstly,
The valid codewords begins with a ‘7’ or Not
Let SA be the number of valid codewords of length n that Do Not begin with 7
SB be the number of valid codewords of length n that begins with 7
Then
Sn = SA + SB
Consider SA [Does Not Begin with ‘7’, i.e. begins with 0 or 1 or ... or 6]
Let us say a valid codeword that begins with 0
The other n-1 octal digits must contain an even number of 7s i.e. Sn-1
As there are 7 such cases
SA = 7Sn-1
Consider SB [Begins with ‘7’]
The other n-1 octal digits must contain an odd number of 7s
For these n-1 octal digits
The number of odds = Total number of codewords
minus The number of evens
minus The number without 7s (not odd or even)
Therefore,
As we are now considering the n-1 octal digits
SB = 8n-1
- Sn-1
Therefore, As
Sn = SA + SB
The Recurrence Relation
Sn = 7Sn-1 + 8n-1
- Sn-1
Simplified
Sn = 6Sn-1 + 8n-1
for n > 1
For The Initial Conditions
When n = 1,
S1 = 7
S1 = 6S0 + 80
Therefore
S0 = 1
ii.
Solution A - IF ZERO 7’S IS NOT CONSIDERED TO BE EVEN
S0 = 0
S1 = 0
Sn = 6Sn-1 + 8n-1
- 7n-1
for n > 1
Let S = s0 + s1x + s2x2 + s3x
3 + ... + snx
n + ...
6xS = 6s0x + 6s1x2 + 6s2x
3+ ... + 6sn-1x
n + ...
It follows
Sn - 6Sn-1 = 8n-1
- 7n-1
for n > 1
By Subtraction
S(1- 6x) = s0 + (s1 - 6s0)x + (s2-6s1)x2 + (s3-6s2)x
3 +... + (sn-6sn-1)x
n + ...
S2 = 1
S3 = 6 + 64 – 49 = 21
S(1- 6x) = (81 -7
1)x
2 +(8
2 -7
2)x
3 +(8
3 -7
3)x
4 +...+ (8
n-1 -7
n-1)x
n +...
S = [ (81 -7
1)x
2 +(8
2 -7
2)x
3 +(8
3 -7
3)x
4 +...+ (8
n-1 -7
n-1)x
n +... ] / (1-6x)
As 1/(1-6x) = 1 + 6x + 62x
2 + 6
3x
3 + ... + 6
nx
n + ...
S = [(81-7
1)x
2+(8
2-7
2)x
3+(8
3-7
3)x
4+..+(8
n-1-7
n-1)x
n+..] *
(1+6x+62x
2+6
3x
3+ .. + 6
nx
n+ ...)
S = 1 [(81-7
1)x
2+(8
2-7
2)x
3+(8
3-7
3)x
4+..+(8
n-1-7
n-1)x
n+..] +
6x [(81-7
1)x
2+(8
2-7
2)x
3+(8
3-7
3)x
4+..+(8
n-1-7
n-1)x
n+..] +
62x
2 [(8
1-7
1)x
2+(8
2-7
2)x
3+(8
3-7
3)x
4+..+(8
n-1-7
n-1)x
n+..] +
63x
3 [(8
1-7
1)x
2+(8
2-7
2)x
3+(8
3-7
3)x
4+..+(8
n-1-7
n-1)x
n+..] +
.
.
6nx
n [(8
1-7
1)x
2+(8
2-7
2)x
3+(8
3-7
3)x
4+..+(8
n-1-7
n-1)x
n+..] +
...
= (8-7)x2 + (8
2-7
2+6(8-7))x
3 + (8
3-7
3+6(8
2-7
2)+6
2(8-7))x
4 +
(84-7
4+6(8
3-7
3) +6
2(8
2-7
2) +6
3(8-7))x
5 + ... +
[8n-1
-7n-1
+6(8n-2
-7n-2
) +62(8
n-3-7
n-3)+...+6
n-3(8
2-7
2)+6
n-2(8-7) ]x
n +...
Therefore (before simplification) the closed form solution of the recurrence relation is
[ 8n-1
-7n-1
+6(8n-2
-7n-2
) +62(8
n-3-7
n-3)+...+6
n-3(8
2-7
2)+6
n-2(8-7) ]
Simplified
[ 60(8
n-1-7
n-1)+6(8
n-2-7
n-2) +6
2(8
n-3-7
n-3)+...+6
n-3(8
2-7
2)+6
n-2(8-7) ]
2
0
1212 )78(6n
k
knknk
2
0
11 )78(6n
k
knknk
The closed form solution of the recurrence relation is
2
0
11 )78(6n
k
knknk
Solution B - IF ZERO 7’S IS CONSIDERED TO BE EVEN
S0 = 1
S1 = 7
Sn = 6Sn-1 + 8n-1
for n > 1
Let S = s0 + s1x + s2x2 + s3x
3 + ... + snx
n + ...
6xS = 6s0x + 6s1x2 + 6s2x
3+ ... + 6sn-1x
n + ...
It follows
Sn - 6Sn-1 = 8n-1
for n > 1
By Subtraction
S(1- 6x) = s0 + (s1 - 6s0)x + (s2-6s1)x2 + (s3-6s2)x
3 +... + (sn-6sn-1)x
n + ...
S2 = 72 + 1 = 50
S3 = 73 + 3x7 = 364
S(1- 6x) = 1 + x + 81x
2 + 8
2x
3 + 8
3x
4 + ... + 8
n-1x
n +...
S = [1 + x + 8x2 + 8
2x
3 + 8
3x
4 + ... + 8
n-1x
n + ... ] / (1-6x)
As 1/(1-6x) = 1 + 6x + 62x
2 + 6
3x
3 + ... + 6
nx
n + ...
S = [(81-7
1)x
2+(8
2-7
2)x
3+(8
3-7
3)x
4+..+(8
n-1-7
n-1)x
n+..] *
(1+6x+62x
2+6
3x
3+ .. + 6
nx
n+ ...)
S = 1 [1 + x + 8x2 + 8
2x
3 + 8
3x
4 + ... + 8
n-1x
n + ...] +
6x [1 + x + 8x2 + 8
2x
3 + 8
3x
4 + ... + 8
n-1x
n + ...] +
62x
2 [1 + x + 8x
2 + 8
2x
3 + 8
3x
4 + ... + 8
n-1x
n + ...+
63x
3 [1 + x + 8x
2 + 8
2x
3 + 8
3x
4 + ... + 8
n-1x
n + ...+
.
.
6nx
n [(1 + x + 8x
2 + 8
2x
3 + 8
3x
4 + ... + 8
n-1x
n + ...] +
...
= 1 + (1+6)x + (8+6+62)x
2 + (8
2+6(8) +6
2+6
3)x
3 +
(83+6(8
2)+6
2(8)+ 6
3 +6
4)x
4 +
(84+6(8
3) +6
2(8
2) +6
3(8) + 6
4 +6
5)x
5 +
... +
[8n-1
+6(8n-2
) +62(8
n-3)+...+6
n-3(8
2)+6
n-2(8) + 6
n-1 +6
n ]x
n +...
Therefore (before simplification) the closed form solution of the recurrence relation is
[ 8n-1
+6(8n-2
) +62(8
n-3)+...+6
n-3(8
2)+6
n-2(8) + 6
n-1 +6
n ]
Simplified
[ 608
n-1+6
1 (8
n-2) +6
2(8
n-3)+...+6
n-3(8
2)+6
n-2(8
1) + 6
n-1(8
0) +6
n ]
nn
k
knk 6)8(61
0
1
The closed form solution of the recurrence relation is
1
0
1 )8(66n
k
knkn
Question 2 [2 mks]
a. Determine the limit of f(x) as x for the following:
33
5)(
x
xxf [1]
b. For the sequence a and b defined by
a1 = 2, an = 3an – 1, n ≥ 2, and bn = 2n (n – 1)
Find ))((7
3
5
2
j
j
i
i ba [1]
Solution 2
[a. Correct solution - 1 mark ]
[ Where question is attempted but incorrect - ½ mark ]
[b. Correct solution - 1 mark ]
[ Where question is attempted but incorrect - ½ mark ]
a. 33
5)(
x
xxf
Dividing numerator and denominator by x, we have
x
xf3
3
5)(
As x →∞, x
3→0
3
5
33
5)( limlim
x
xxf
xx
b. ))((7
3
5
2
j
j
i
i ba = (a2 + a3 + a4 + a5) * (b3 * b4 * b5 * b6 * b7 )
= (6 + 18 + 54 + 162) * (16 * 48 * 128 * 320 * 768)
= 240 * 24159191040
= 5,798,205,849,600
Question 3 [5 mks]
Find a formula for the sequence c defined by
n
i
in bc1
Where b is the sequence 1, 2, 4, 4, 7, 8, 10, … [5]
Solution 3
[For stating an Alternating AP-GP Sequence - 1 mark ]
[First terms a, Common difference d & ratio r, formulae for Sn - 1 mark ]
[Solving Sn to produce correct formulae - 2 marks ]
[Correct combination of AP and GP formulae to produce cn - 1 mark ]
For the sequence b defined by 1, 2, 4, 4, 7, 8, 10, …
b1 = 1,
b2 = 2,
b3 = 4,
b4 = 4
b5 = 7,
b6 = 8,
b7 = 10,
b8 = 16 (assumed)
For odd number indexes in the sequence, we have an Arithmetic Progression, with
a = 1
d = 3
For even number indexes in the sequence, we have a Geometric Progression, with
a = 2
r = 2
We have Alternating AP-GP sequence
For the AP sequence
Sn = (n/2)(2a + (n-1)d)
= (n/2)(2x1 + (n-1)x3)
= (n/2)(2 + 3n - 3)
= (n/2)(3n - 1)
As in our AP formula c1 represents S1 for the odd number indexes
c1 represents S1
c3 represents S2
c5 represents S3 and so on
i.e. cn represents S(n+1)/2
For odd number indexes
Sn = ( n /2)(3n - 1)
By substitution
cn = ( ((n+1)/2) /2)(3((n+1)/2) - 1)
= ( (n+1)/4)((3n+3)/2 - 1)
= ( n/4 + 1/4 )( 3n/2 + ½ )
= ½ ¼ ( n + 1 )( 3n + 1 )
= (1/8)( n + 1 )( 3n + 1 )
For the GP sequence
Sn = a(rn - 1)/(r – 1)
= 2(2n - 1)/(2 – 1)
= 2(2n - 1)
As in our GP formula c1 represents S1 for the even number indexes
c2 represents S1
c4 represents S2
c6 represents S3 and so on
i.e. cn represents Sn/2
For even number indexes
Sn = 2 (2n - 1)
By substitution
cn = 2 (2n/2
- 1)
When n is odd,
cn = cn (for odd) + cn-1 (for even)
= (1/8)( n + 1 )( 3n + 1 ) + 2(2(n-1)/2
- 1)
When n is even,
cn = cn (for even) + cn-1 (for odd)
= 2(2n/2
- 1) + (1/8)( (n-1) + 1 )( 3(n-1) + 1 )
= 2(2n/2
- 1) + (1/8)( n )( 3n - 3 + 1 )
= 2(2n/2
- 1) + (1/8)( n )( 3n - 2 )
Question 4 [3 mks]
Let f(n) and g(n) be functions defined on the set of positive integers
Prove or disprove the following:
if f (n) = Ο (h(n)) and g(n) = Ο ( k(n))
then f(n)g(n) = Ο (h(n)k(n)). [3]
Solution 4
[Stating f(n) and g(n) in terms of the inequality - 1 mark ]
[Stating that | f(n) | | g(n) | = | f(n) g(n) | for positive integers - ½ mark ]
[Logical steps of the Proof - 1½ marks ]
f(n) = O(h(n))
⇒ | f(n) | ≤ C1 | h(n) |
where C1 is a constant
g(n) = O(k(n))
⇒ | g(n) | ≤ C2 | k(n) |
where C2 is a constant
By Multiplication
| f(n) | | g(n) | ≤ C1 C2 | h(n) | | k(n) |
As f(n) and g(n) are functions defined on the set of positive integers
| f(n) | | g(n) | = | f(n) g(n) | ≤ C1 C2 | h(n) | | k(n) |
∴ | f(n) g(n) | ≤ C1 C2 | h(n) | | k(n) |
| f(n) g(n) | ≤ C3 | h(n) | | k(n) |
where C3 is a new constant
Where h(n) and k(n) are functions defined on the set of positive integers
| f(n) g(n) | ≤ C3 | h(n) | | k(n) | = C3 | h(n) k(n) |
∴ | f(n) g(n) | ≤ C3 | h(n) k(n) |
∴ f(n) g(n) = O(h(n) k(n))
Question 5 [2 mks]
What is the limit of
n
k
k nasx0
? State all necessary
conditions for this limit to exist. [2]
Solution 5
[Correct limit found - 1½ marks ]
[Necessary conditions - ½ mark ]
As n →∞
n
k
kx0
= 1 + x + x 2 + x
3 +…
By Generating Functions definition, nas
1 + x + x 2
+ x 3 +… = 1 / (1 - x)
Condition: x ≠ 1
Question 6 [7 mks]
Use generating functions to find a closed form solution for each of the following
recurrence relations:
i. a0 = 1 and an = 3an-1 + 2 for n ≥ 1 [3]
ii. s0 = 6, s1 = 5 and 9Sn = 6Sn-1 - Sn-2 for n ≥ 0 [4]
Solution 6
[i. Correct initial layout of solution – 1st 2 statements - ½ mark ]
[ Application of Correct combining i.e. Subtraction - ½ mark ]
[ Logical steps towards correct solution - 2 marks]
[ Where full mark is not attained, but there was simplification of solution included ]
[ additional ½ mark ]
[ii. Correct initial layout of solution – 1st 3 statements - 1 mark ]
[ Application of Correct combining i.e. Subtraction & Addition - 1 mark ]
[ Logical steps towards correct solution - 3 marks ]
[ Where full mark is not attained, but there was simplification of solution included ]
[ additional ½ mark ]
i. Given
a0 = 1
an = 3an-1 + 2 , n≥1
Consider the generating function
f(x) = a0+a1x+ a2x2+…+ anx
n+…
3xf(x) = 3a0x+3a1x2+…+3an-1x
n+…
It follows
an - 3an-1 = 2
Subtracting…
f(x) - 3xf(x) = a0 + (a1- 3a0)x + (a2- 3a1)x2+…+ (an- 3an-1)x
n +…
Now Substituting a0 = 1, a1 = 3a0 ,…, an = 3an-1
(1-3x)f(x) = 1 + 2x + 2x2+…+ 2x
n +…
= -1 + 2 (1 + x + x2+…+ x
n +…)
f(x) = (-1 + 2 (1 + x + x2+…+ x
n +…)) * (1 / (1-3x))
f(x) = (-1 + 2 (1 + x + x2+…+ x
n +…)) * (1 + 3x + 3
2x
2+…+ 3
nx
n +…)
f(x) = -1 * (1 + 3x + 32x
2+…+ 3
nx
n +…)
+ 2 [ 1 * (1 + 3x + 32x
2+…+ 3
nx
n +…)
+ x * (1 + 3x + 32x
2+…+ 3
nx
n +…)
+ x2 * (1 + 3x + 3
2x
2+…+ 3
nx
n +…
…
+ xn * (1 + 3x + 3
2x
2+…+ 3
nx
n +…) ]
f(x) = -1 * (1 + 3x + 32x
2+…+ 3
nx
n +…)
+ 2 [ 1 + (3 + 1)x + (32+3+1)x
2 + …+ (3
n+3
n-1+…+3
2+3+1) x
n +… ]
Therefore the closed form solution is
[ -3n + 2 (3
n+3
n-1+…+3
2+3+1) ]
or
n
k
kn
0
323
ii. S0 = 6
S1 = 5 and
9Sn = 6Sn-1 - Sn-2 for n ≥ 2
Let S = s0 + s1x + s2x2 + s3x
3 + ... + snx
n + ...
9S = 9s0 + 9s1x + 9s2x2 + 9s3x
3 + ... + 9snx
n + ...
6xS = 6s0x + 6s1x2 + 6s2x
3+ . . . + 6sn-1x
n + ...
x2S = s0x
2 + s1x
3+ . . . + sn-2x
n + ...
9Sn - 6Sn-1 + Sn-2 = 0
By Subtraction and Addition
S(9- 6x+x2) = 9s0 + (9s1 - 6s0)x + (9s2-6s1+s0)x
2 + ... + (9sn-6sn-1 + sn-2)x
n + ...
= 54 + 9x
Dividing through by 9
S(1- (2/3)x+(1/9)x2) = 6 + x
S(1-(1/3)x) (1-(1/3)x) = 6 + x
S = (6 + x) / [(1-(1/3)x)(1-(1/3)x)] or (6 + x) / [(1-(1/3)x)]2
As 1/(1-(1/3)x) = 1 + (1/3)x + (1/3)2x
2 + (1/3)
3x
3 + ... + (1/3)
nx
n + ...
S = (6+x)(1+(1/3)x+(1/3)2x
2+ ...+(1/3)
nx
n + ...) (1+(1/3)x+(1/3)
2x
2+ ... +(1/3)
nx
n + ...)
= (6+x) * [
1 (1 + (1/3)x + (1/3)2x
2 + (1/3)
3x
3 + ... + (1/3)
nx
n + ...) +
(1/3)x (1 + (1/3)x + (1/3)2x
2 + (1/3)
3x
3 + ... + (1/3)
nx
n + ...) +
(1/3)2x
2 (1 + (1/3)x + (1/3)
2x
2 + (1/3)
3x
3 + ... + (1/3)
nx
n + ...) +
(1/3)3x
3 (1 + (1/3)x + (1/3)
2x
2 + (1/3)
3x
3 + ... + (1/3)
nx
n + ...) +
.
.
(1/3)nx
n (1 + (1/3)x + (1/3)
2x
2 + (1/3)
3x
3 + ... + (1/3)
nx
n + ...)+ ]
= (6+x) [1+2(1/3)x + 3(1/3)2x
2 + 4(1/3)
3x
3+...+ n(1/3)
n-1x
n-1+(n+1)(1/3)
nx
n+...]
= 6 * [1+2(1/3)x + 3(1/3)2x
2 + 4(1/3)
3x
3+...+ n(1/3)
n-1x
n-1+(n+1)(1/3)
nx
n+...]
+ x [1+2(1/3)x + 3(1/3)2x
2 + 4(1/3)
3x
3+...+ n(1/3)
n-1x
n-1+(n+1)(1/3)
nx
n+...]
= 6 + [6*2(1/3)+1]x + [6*3(1/3)2+2(1/3)]x
2 + [6*4(1/3)
3+3(1/3)
2]x
3+
+ [6*5(1/3)4+4(1/3)
3]x
4+...
+ [6*(n+1)(1/3)n+n(1/3)
n-1]x
n+...
Therefore (before simplification) the closed form solution of the recurrence relation is
[6 * (n+1) (1/3)n
+ n (1/3)n-1
]
Simplified
[6 * (n+1) (1/3)n-1+1
+ n (1/3)n-1
]
[(1/3)n-1
(6 * (n+1) (1/3)1
+ n) ]
[(1/3)n-1
(6 * (1/3)1 (n+1)
+ n) ]
[(1/3)n-1
(2 * (n+1) + n) ]
[(1/3)n-1
(3n+2) ]
The closed form solution of the recurrence relation is
[ (1/3)n-1
(3n+2) ]
or [ (1/3)n(1/3)
-1 (3n+2) ]
or [ (1/3)n(3)
(3n+2) ]
or [ (1/3)n(9n+6) ]
Question 7 [8 mks]
Let a,b,c be integers such that a ≥ 1, b > 1 and c > 0. Let f: N → R be functions
where N is the set of Natural numbers and R is the set of Real numbers
such that
f(1) = c and f(n) = af(n/b) + c
for n = bk, where k is a positive integer greater than 1.
(a) By using the principles of Recurrence Relation, find a general formula
for f(n) [4]
(b) Hence show that if a ≠ 1, then f(n) = )(1
)1( loglog
aa
b
b
na
anc
[4]
Solution 7
[(a) Logical steps outlined towards finding general equation - 3 marks ]
[ Finding general equation f(n) - 1 mark ]
[(b) Making substitutions and finding f(n) = calog
bn + c
1log
0
n
i
ib
a - 1 mark ]
[ Proving Big-Oh - 2 marks ]
[ Proving Omega - 1 mark ]
[Where error is made in any of the above but proofs for Big-Oh and Omega were
attempted and full mark is not attained - ½ mark ]
(a) f(n) = a f(n/b) + c .....1
Substituting for f(n/b)
= a [ a f(n/b2) + c ] + c
= a2 f(n/b
2) + c(a + 1) .....2
Substituting for f(n/b2)
= a2 [ a f(n/b
3 ) + c ] + c(a + 1)
= a3 f(n/b
3 ) + c(a
2 + a + 1) .....3
Substituting for f(n/b3)
= a3 [ a f(n/ b
4) + c ] + c(a
2 + a + 1)
= a4 f(n/b
4 ) + c(a
3 + a
2 + a + 1) .....4
= ......
Given that k is a positive integer greater than 1
f(n) = ak f(n/b
k) + c
1
0
k
i
ia
(b) As n = bk
n/bk = 1 AND logb n = k
As k = logb n AND n/bk = 1 AND if a ≠ 1 AND f(1) = c
f(n) = ak f(n/b
k) + c
1
0
k
i
ia
= ak f(1) + c
1
0
k
i
ia
= ak * f(1) + c * [a
k-1 + a
k-2 +…+ a
3 + a
2 + a + 1]
As f(1) = c, and k = logb n
f(n) = calog
bn + c
1log
0
n
i
ib
a
f(n) = calog
bn + c [a
logb
n-1 + a
logb
n-2 +…+ a
3 + a
2 + a + 1]
= c[alog
bn + a
logb
n-1 + a
logb
n-2 +…+ a
3 + a
2 + a + 1]
Further, as logb n = k AND k is a positive integer greater than 1
f(n) ≤ c[alog
bn + a
logb
n + a
logb
n +…+ a
logb
n + a
logb
n + a
logb
n + a
logb
n]
≤ c(n+1)alog
bn
Therefore
f(n) = O(alog
b n
)
Likewise
f(n) = calog
bn + c
1log
0
n
i
ib
a
f(n) ≥ calog
bn
Therefore
f(n) = Ω(alog
b n
)
Hence
f(n) = Θ(alog
b n
)
Question 8 [4 mks]
Consider the geometric series:
3 + 12/7 + 48/49 + 192/343 + …
i. Determine a formula for Sn
where Sn is the sum of the first n terms of the series? [3]
ii. What is the limit of Sn [1]
Solution 8
[i. Common ratio, r - ½ mark ]
[ Correct formula for Sn - ½ mark ]
[ Solving Sn to produce a correct formula - 2 marks ]
[ii. Correct formula for |r| < 1 - ½ mark ]
[ Correct solution for limit of Sn - ½ mark ]
i. For a geometric progression
un = arn-1
u1 = a = 3
u2 = ar = 12/7
r = ar / a = (12/7) / 3
= 12/21
= 4/7
Sn = a(rn - 1)/(r - 1)
Sn = 3((4/7)n - 1) / (4/7 - 1)
= 3((4/7)n - 1) / -3/7
= 3(1 - (4/7)n) / 3/7
= 3(1 - (4/7)n) * 7/3
= 7(1 - (4/7)n)
or
7 - 7(4/7)n
or
-7( (4/7)n - 1)
or
-7(4/7)n + 7
ii. Where |r| < 1
Limit of Sn = a / (1 – r)
= 3 / (1 – 4/7)
= 3 / (3/7)
= 7
Question 9 [6 mks]
Find the generating function for the sequence
1, 4, 13, 28, 49, … [6]
Solution 9
[Logical steps towards correct solution - 3 marks ]
[Correct interpretation of operations and computation - 2 marks ]
[Correct Final Solution - 1 mark ]
We have 1, 1, 1, 1, … ≡ 1 + x + x2 + x
3 + x
4 + …≡
x1
1
By Differentiating
1, 2, 3, 4,5 … ≡ 2)1(
1
x
By Right-shifting, 1 place
0, 1, 2, 3, 4, … ≡ 2)1( x
x
By Differentiating, again
For LHS
1, 4, 9, 16, …
For RHS
2
2)1(
)1(
xxx
xyLet
dx
dp
dp
dvU
dx
duV
dx
dythen
dx
dp
dp
dv
dx
dvand
pvxpLet
Further
dx
dvU
dx
duV
dx
dythen
vuyxvxuLet
2
2
,1
,)1(,
3
3
32
32
32
22
)1(
1
)1(
21
)1(
2
)1(
1
)1(2)1(
)1()2()1()1(
)1()()1(
x
x
x
xx
x
x
x
xxx
pxx
dx
xd
dp
pdx
dx
dxx
dx
dy
Therefore
1, 4, 9, 16, 25,… ≡ 3)1(
1
x
x
By Right-shifting, 1 place
0, 1, 4, 9, 16,,… ≡ 3)1(
)1(
x
xx
By Scaling, with factor of 3
0, 3, 12, 27, 48, … ≡ 3)1(
)1(3
x
xx
By Addition of generating function 1, 1, 1, 1, ...
For LHS
1, 4, 13, 28, 49, …
For RHS
3
2
3
22
3
2
3
)1(
14
)1(
2133
)1(
)1()1(3
1
1
)1(
)1(3
x
xx
x
xxxx
x
xxx
xx
xx
1, 4, 13, 28, 49, … ≡ 3
2
)1(
14
x
xx
Therefore the generating function for the sequence 1, 4, 13, 28, 49, … is 3
2
)1(
14
x
xx