Friday, May 27, 2011

Your (Hopefully Correct?) Guide Answer

Hi, Hin Hin. I finally got some times now to help you with your interview question that day.

You say you were given the series 0,1,1,2,3,5,8,13,21,34,55

Create an algorithm or Mathematics expression for the database

First we start from 0 and give i name as t0

t0  , t1  , t2  , t3  , t4  , t5  , t6  , t7  , t8  , t9  , t10
0     1      1     2      3     5      8     13    21    34    55

We can see that pattern of it sums up to t2= t0+t1, t3=t2+t1 , t4=t3 +t2 and such.
We may not learn it in school but there is name for it, it is called Fibbonacci Sequences

It is defined in this way, if you remembered it.

So the mathematics expression part is solved.By the way, tn=t (n-2)+t(n-1) is also correct. And you said that he do not care what language that you used, it is just syntax, so I used Java  pseudocode (For easy references ^_^)

class Fibbonacci {
public static main void main(String [] args){

     //initialize the t0=0, t1=1 and t2 =2
//print out 0 and 1 first

   while(t2<100){

//offset t0=t1, t1=t2 and declares t2=t1+t0
                         }
//print out t2 and , 
                                                                }
                          }

*If you confuse which open and closed loops paired together, see the indent, same indent means it is a pair. 

Jia yu on your job interview! Sorry, I don't know anything about database as now, so cant help you .  

No comments:

Another random post to read ? Come !

Related Posts with Thumbnails