Sie sind auf Seite 1von 3

Name: Azri Bin Mohd Khanil

Matric No: WEK110006


[Question 1]
Sum of cubes for the first natural numbers can be computed using the
following equation:
N

S3(N) =

i3
1

Part (a)
Draw the flow chart for computing 3() using while-loop.

Part (b)
Draw the flow chart for computing 3() using recursion.

Part (c)
Write 3() using recurrence relation (refer to class note for hint).
N

S3(N) =

i
1

= 13+23+...+n3 =

n(n+1)
2

13 = 1
13+23=9
13+23+33=36
13+23+33+43=100
13+23+33+43+53=225
In conclusion it is the square of the nth triangle number.
2

eg. i) S3(5) = (1+2+3+ 4+5)

152

2
ii) S3(7) = (1+2+3+ 4+5+6+ 7) =

= 225
2

28

= 784

Part (d)
Write 3() as a close-form equation.

S3(N) =

i 3=
i=1

( )

i =
i=1

n2 ( n+ 1 )
4

[Question 2]
Fibonacci series is defined by the equation () = ( 1) + ( 2) for 3
,
(1) = 1 and (2) = 2. Note that this recurrence relation occurs in one
dimension, i.e., in the
parameter .
Given the values recorded in Table 1 below, find the recurrence relation (, )
in two
dimension. For simplicity, let and capture the changes across columns
(horizontal direction) and rows (vertical direction), respectively.
Ans:
F( n,t ) = F(n -1, t) + F(n, t -1)

Das könnte Ihnen auch gefallen