Minggu, 21 Desember 2008

APLICATION DYNAMIC PROGRAM

APLICATION DYNAMIC PROGRAM FOR A COUNT FIBONANCI NUMBER AND BINOMIAL COEFFICIENT
ABSTRAC
The working paper discus that implementation dynamic programming . the discussion working paper counting fibonanci number and binomial coefficient with dynamic programming. Fibonanci number and binomial coefficient is numeral rekursif. We can count fibonanci number and binomial coefficient with rekursif algorithm, apropate with definite that numeral. While, if we more pay attention rekursif algorithm for two problems very not efficient calculation continued.
This is slow computation for more values. Rekursif algorithm can used for count Fibonanci number and binomial coefficient have exponential complexity. With dynamic programming we can reduction so we have complexity linear solution algorithm. Calculation above can losted.
INTRODUCTION
Dynamic programming found by Richard bellman at 1953, it is one method solution when solution of problem can meet decisiomn series have connect. Dynamic programming is one of them effective method used usually for simplification rekursif problems. Like that greedy algorithm, dynamic programming also one of approach for finish optimation problem. But,the greedy method just only decisions series. Dynamic programming focus for overlapping sub problems. Decisions series make from optimal structure, when optimum solution can used for find optimum solution for totalyti problems. The opticasion dynamic programming very large. For example, simple,for count Fibonacci number and binomial coefficient. Also other algorithm based from dynamic programming like cooke-younger-kasami algorithm for determine what one string can accept that context-free grammar, viterby algorithm for method hidden markow. Erly algorithm for charts passer, nedleman- wunch algorithm used bioninformatic, floyd’s all-pairs algorithm for hunt short flash, selingger algorithm for query optimation . it is based data for evaluated B. spline curve ,and etc.
Dynamic Programming For count Fibonacci Number
One of them application form dynamic programming is counting Fibonacci number . dynamic programming is alternative for count Fibonacci number with fast, substitute for rekursif algorithm very inefficient
Fibonancci Number
0,n= 0
F(n)=1 n=1
F(n-1)+ F(n-2), n>1
So, the numbers is sum form last two numeral
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,
987, 1597, 2584, 4181, 6765, 10946, 17711, 28657,
46368, 75025, 121393, 196418, 317811…
Fibonacci number have an interesting characteristic
We can devided one numeral in above
This facta, the numeral valuabe permanent after the numeral to-13 in above Fibonacci number . the number called golden ratio (phi), whwn Fibonacci number also have identity:
1. F(n + 1) = F(n) + F(n − 1)
2. F(0) + F(1) + F(2) + … + F(n) = F(n + 2) − 1
3. F(1) + 2 F(2) + 3 F(3) + … + n F(n) = n F(n + 2) −
F(n + 3) + 2
4. F(0)2 + F(1)2 + F(2)2 + … + F(n)2 = F(n) F(n + 1)
Application Dynamic programming
From the definition of fibonacci number , we can make rekursif algorithm for count Fibonacci number like that
Function Fibonacci (input n=integer)
Type data can substituted with long interger or an other.
Input : n
Out put : Fibonacci number to-n
Declaration algorithm
If n=0 then
Return 0
Else if n=1 then return 1else
Return Fibonacci (n-1)+ Fibonacci (n-2)
End if
If T (n) is time for count F(n) is Fibonacci number to-n, so by using above function clear that
T(n) = T(n – 1) + T(n – 2)
And
T(1) = T(2) = c
When C is constant, because that
T(n) = c F(n),so
T(n) = O(F(n)) = O(1,618...n)


The simple function have exponential time complexity. So algorithm like that can used, but very not effective for more than value. We can see, that Fibonacci (n+1) must carry out all counting fgrom Fibonacci (n) and Fibonacci (n+1) . and in count Fibonacci number continued.
With dynamic programming, we can repair rekursif algorithm, so computation become efficient. We can use two concept in dynamic programming : top-dow and botton up. Solution with two concept explained like that :
With top-down approach

In here, we use one array, exemple FIB array have measurement-n when FIB(i) have contens Fibonacci number to(i+1) , that algorithm function (input interger)
(count Fibonacci number to-n with top-down approach)
Input(n)
Out put : Fibonacci number to-n
Declaration
I= interger
FIB : array [i….n] of interger
Algorithm if n=0 then
return 0
else if n=1 or n=2 then
return 1
else
Fib[1] �� 1
Fib[2] �� 1
for i��3 to n do
Fib[i] �� Fib[i-1] + Fib[i-2]
endfor
return Fib[i]
endif
With that , we can have value Fib[3], Fib[4], and etc, we keep that value in array. While loop finish, the function will restore finish element of array, it is Fibonacci number to-n that counted.
With bottom-up approach
There, we count Fibonacci small then, then calculation more then value from previously values. This is a repair from previously concept when this array, it lost by us.
The algorithm like
Funtion Fibonacci (input n ;interger)
(count Fibonacci number to-n with dynamic programming(bottom-up approach))
Input=n
Out put : Fibonacci number to-n
Declaration
I=interger
PrevF,currF,new F : interger
Algorithm
prevF �� 0
currF �� 1
for i��2 to n do
newF �� prevF + currF
prevF �� currF
currF �� newF
endfor
return currF
two mentioned approaches have equel complexity , it is 0(n). linear complexity and it is more than rekursif algorithm. Sed difference just used memory, whwn top-down, we need much memory for array Dynamic programming, we can lost calculation.

Dynamic programming foe count binomial coefficient
Binomial coefficient
In mathemathics , first combinational, binomial coefficient fron numeral and interger numeral k is sum combination . such as ,if given interger s including zero, method choose k ball equal binomiqal coefficient.
Binjomial coefficient defined that
for n ≥ k ≥ 0 and
for k < 0 or k > n.
For value n and k non-negative, so we have albert Ion Eiting hausen notasion. It is introduce by Albert at 1826. An other notasion usually used like c(n,k),nCk, or C nk (C for combination)
Applycation Dynamic pRogaramming
From definition of binomial coefficient , we can make algorithm like
Function binomial (input n,k intrger)
(count buinomial coefficient from (n,k) with rekursif. For more than numeral, type data can subtitude witjh longinterger or an other)
Input :n,k
Out-put: binomial coefficient (n,k)
Declaration
Algorithm if nreturn 0
else if k=0 or k=n then
return 1
else
return Binomial(n-1,k-1) +
Binomial(n-1,k)
Endif
Complexity of algorithm above is
T(n,k) = T(n – 1, k – 1) + T(n – k, k)
or
T(n,k) = O(nk)

With algorithm that, much computation continued
Fir example, counting C(5,3) with counting Fibonacci number like in counting Fibonacci number , we can repair algorithm with dynamic programming. Principles used is:
Make matriks (n+1) × (k+1)f0r keep crop of count
Inisialitation matriks with smaller from problems instansiation.
Set element matriks , use crop count. One element counted just only one.
Finish value from count is solution from problem
In tgere, we implementation interatif, not rekursif
That explained
With top-dow approach
The algorithm
Function binomial (input n, k : interger)
{count binomial coefficient from (n, k) with dynamic programming , tpo-down approach}
Input : n , k
Output :binomial coefficient (n,k)
Declaration
i,j : integer
Bin : array [1..n+1][1..k+1] of integer
Algoritma
{inisialisasi matriksa}
for i��1 to n+1 do
for j��1 to k+1 do
Bin[i][j] �� 0
endfor
endfor
n – 1
k – 1
n – 1
k
+
, 0 < k < n
1 , k=0 or k=n
n =k
binomial coeeficient written with

C(5,3)
C(4,2) C(4,3)
C(3,1) C(3,2) C(3,2) C(3,3)
{count binomial coefficient}
if n=k or k=0 then
return 1
else if Bin[n+1][k+1]>0 then
return Bin[n+1][k+1]
else
Bin[n+1][k+1] �� Binomial[n][k] +
Binomial[n][k-1]
return Bin[n+1][k+1]

With bottom-up approach
The algorithm
Function binomial (input n,k : interger)
{count binomial coefficient from(n, k) with bottom-up appriach}
Input : n,k
Output : binomial coefficient (n, k)
Declaration
i,j : integer
Bin : array [1..n+1][1..k+1] of integer
Algoritma
{inisialisasi matriksa}
for i��1 to n+1 do
for j��1 to k+1 do
Bin [i][j] �� 0
endfor
endfor
{menghitung koefisien binomial}
for i��1 to n+1 do
for j��1 to (Min(i,k)+1) do
if j=0 or j=k then
Bin[i][j] �� 1
else
Bin[i][j] �� Bin[i-1][j-1] +
Bin[i-1][j]
endif
endfor
endfor
return Bin[n+1][k+1]
two concept have equel complexity it is O(nk), or at problems (k=n/2)
that complexity O(n2). This complexity more better than rekursif algorithm

Conclution
Used dynamic programming for count fibonaccy number and binomial coefficient more effective beter than rekursif algorithm.

Video 1: “Some Function Problem”

Example 1

The graph above shows the graph of y=g(x) if the function h is defined by h(x)=g(2x)+2. What is the value of h(1)?

Information on the graph h(x)=g(2x)+2. We are looking for h(1), the function h(1)=g(2)+2. Based on the graph that at g(2)=1, so we have h(1)=1+2 and final answer h(1)=3.

Example 2

Let the function f be defined by f(x)=x+1 if 2f(p)=20. What is the value of f(3p)?

We looking for f(3p), but first we are looking for what is f when x=3p. we have f(x)=x+1 and similar with 2f(p)=20 equal f(p)=10. Substitute x with p, the function become f(p)=p+1. We have f(p)=10 and the function become f(p)=p+1=10, we get p=1. Substitute p=1 into x=3p, we get x=27, that not final answer. The last, insert x=27 into function f(x)=x+1, so we get f(27)=28, that the final answer.

Example 3

In the xy coordinate plane, the graph of x=y2-4 intersect l at (0,p) and (5,t). what is the greatest possible value of slope of l?

We looking for greatest m. we have x=y2-4 and line l. Line l have slope m which function m=y2-y1 over x2-x1. The graph of x=y2-4 intersect l at (0,p) and (5,t), to looking for value of p and t, we are substitute (0,p) and (5,t) into x=y2-4, so we get p=2 and t=3. And than, apply (0,2) and (5,3) into m=y2-y1 over x2-x1, the function become 3-2 over 5-0 or 1 over 5. So, the greatest value of the slope of l is 1 over 5.

Video 2: “Factoring of polynomial”

One way to find factorial of polynomial is to form algebraic long division, for example lets try to see if x-3 a factor of x3-7x-6.

When dividing x-3 into x3-7x-6, first serret the problem long division problem at elementary school. Here is dividing x-3 into x3+0x2-7x-6, the zero is there because no second degree term. Now, you must ask your self what times x give x3, of course it’s x2. So you write x2 as a part equation and then multiply x-3 by x2 which give you x3-3x2, which you subtract from x3+0x2-7x-6 to get 3x2. Bring it down, -7x, you have x3-7x. Just looking the first term, x goes into 3x2, 3x times, 3x is the next part the answer. Multiply x-3 by 3x for predict x2-9x, subtracting and you get 2x and bring down -6, so you get 2x-6. Now see x-3 divide evenly into 2x-6 which equal 2 without remainder. So the solution for the long division problem x3-7x-6 divide by x-3 is x2+3x+2.

Since x-3 divide into x3-7x-6 evenly without remainder, then x-3 is a factor of x3-7x-6. The equation x2+3x+2 is also a factor of x3-7x-6. We know now that x3-7x-6=(x-3)( x2+3x+2). The quadratic expression, x2+3x+2, can be factor into (x+1)(x+2). So, x3-7x-6=(x-3)( x+1)(x+2). Bring the factor x3-7x-6 to zero, we get 0=(x-3)(x+1)(x+2), thus either x-3=0 or x+1=0 or x+2=0. Solving all the equation for x, we get x=3, x=-1, x=-2. The roots of x3-7x-6 are 3, -1, -2.

Now, there 3

Video 3: “Precalculus Graph”

Let’s begin by discussion graph of a rational function which can have discontinuities, why?, because rational function has a polynomial in the denominator.

It possible some value of x will lead division by zero. Let’s if f of x equal x plus 2 over x minus 1, when x=1 the function value become 1+2 over 1-1, which is 3 over 0 with zero in denominator. For this function choosing x=1 is a bad idea. This function will be break in a graph.

Let’s insert 0 into f(x) equal x+2 over x-1, so we get 0+2 over 0-1 which is 2 over -1 or -2. So, you can draw in a graph at (0,-2), and let’s to try insert x=1 this time you get 1+2 over 1-1 which equal 3 over 0. That as we know is impossible, it’s mean you can’t compute value when x=1. In the graph x=1 doesn’t have value.

Rational function don’t always work in this way. Take the graph function f(x) equal 1 over x2+1, not all rational function will give zero in denominator. Don’t forget the general rule, rational function denominator can be zero.

A break can show up in two ways. The simply type break is missing point in the graph. The function y equal x2-x-6 over x-3 will be break when x=3 because the function become zero over zero, that is not possible, not feasible and not allowed. This typical example is missing point syndrome.

When result is zero over zero, that possible to factoring top and button rational function and simplify. In example hand, y=x2-x-6 over x-3, top factor (x-3)(x+2), (x-3) in the top cancel with the button, so the function simplify become y=x+2.

The other one is removable singularity appear simply as missing on a graph and of course when x lead 0 over 0, for this kind the break if you factor and simplify rational function, division by 0 can be avoided.

roots for the 3rd degree equation. Here remember quadratic (2nd degree) equation always have at most 2 roots. A 4th degree equation would have four or fewer roots and so on. The degree of a polynomial equation always limits the number of roots.

Let’s review long division process for a 3rd order polynomial, first find a partial equation of x2 by dividing x into x3 to get x2. Then multiply x2 by the divisor and subtract the product from the divided. Repeat the process until you either “clear it out” or “reach a remainder”.

Video 4: “Inverse Function and Existence of an inverse”

Some functions do not have inverse functions. For example, consider f(x) = x2. Used horizontal test there are two numbers that f same value, example f(2) = 4 and f(-2) = 4. If f had an inverse, then the fact that f(2) = 4 would imply that the inverse of f takes 4 back to 2. On the other hand, since f(-2) = 4, the inverse of f would have to take 4 to -2. Therefore, there is no function that is the inverse of f. The function f(x) = x2 have inverse in interval 0<=x, so the function is invertible.

Let start with function y=2x-1. Look at the graph of f is a line with slope 2, so it passes the horizontal line test and does have an inverse.

There are two steps required to evaluate f at a number x. First we multiply x by 2, then we subtract 1. Thinking of the inverse function as undoing what f did, we must undo these steps in reverse order. The steps required to evaluate f-1 are to first undo the subtracting of 1 by adding 1. Then we undo multiplication by 2 by dividing by 2.

Therefore, x = (y +1)/2 and then interchange y and x. the function become y=(x+1)/2.

We have function f(x)=2x-1 and the other function g(x)=x+1 over 2. If g=f-1 and substitute g(x) into f(x), so we get f(g(x))=f(f-1(x)) and substitute f(x) into g(x) and we get g(f(x))=f-1(f(x))=x.