View Single Post
Old 04-12-2013, 01:49 PM   #17
reuben_tate
Kawaii Desu Ne?
Retired StaffFFR Veteran
 
reuben_tate's Avatar
 
Join Date: Dec 2007
Location: The Kawaiian Island~
Age: 30
Posts: 4,182
Default Re: Teach me CS stuff for interviews

Also, simply memorizing the time efficiencies of common algorithms may not be good enough, you should be able to look at the code yourself and do some analysis to determine the Big-O yourself. Your interviewer may hand you some code and ask you what the worst case time efficiency is.

These are from a simple review quiz I had on my first day of class. If you can do these you should be fine.

Find the Big-O of the following functions / code fragments
Code:
static long Fibonacci(int n) {
    if (n==1||n==2) return 1;
    return Fibonacci(n-2)+Fibonacci(n-1);
}
O(2^n)


Code:
for (int i=0,j=0; i<n; i++)
    for (double d=1; d<n; d*=2)
        j++;
O(n*logn)

Code:
int[] a=new int[n];
for (int i=4;i<n;i++) {
    for (int j=i-3,sum=a[i-4];j<=i;j++)
        sum+=a[j];
}
O(n)

Code:
private static long gcd(long n,long r) {
    if (r==0) return n;
    return gcd(r,n%r);
}
O(log(n))
__________________
AMA: http://ask.fm/benguino

Not happening now! Don't click to join!



Quote:
Originally Posted by Spenner View Post
(^)> peck peck says the heels
Quote:
Originally Posted by Xx{Midnight}xX
And god made ben, and realized he was doomed to miss. And said it was good.
Quote:
Originally Posted by Zakvvv666
awww :< crushing my dreams; was looking foward to you attempting to shoot yourself point blank and missing
reuben_tate is offline   Reply With Quote