You could update fibb[n] before returning fib(n-1) + fib(n-2)
int fib(int n)
{
if ( n = 1 )
{
fibb[1]=n;
return n;
}
if (fibb[n] ! = 0 ) {
//return fibs(n-1)+fibs(n-2);
}
On Sunday, October 21, 2012 7:46:43 AM UTC-4, rahul sharma wrote:
You could store fibs[n-1] + fibs[n-2] in fibb[n] before returning.
int fib(int n)
{
if ( n = 1 )
{
fibb[1]=n;
return n;
}
if(fibb[n] != 0) {
return fibb[n];
}
fibb[n] = fibs[n-1] + fibs[n-2];
return fibb[n];
//return fibs(n-1)+fibs(n-2);
}
here's an O(lgn) soln :
matrix form of fib :
http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form
and then use the divide and conquer for calculating (A)^n in O(lgn).
Thanks
On Sun, Oct 21, 2012 at 7:10 PM, rahul sharma rahul23111...@gmail.comwrote:
I have implemented this code below:-
int temp = {[1(j-+1)]i-1};
Here temp is a number with all the bits set between positions i j [both
inclusive]
temp = ~temp;
N = N temp; // here we are clearing all the bits of N from
position i to j
temp = temp | M; // now we are taking the bit pattern from M into temp
this is from KR exercise :)
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Wed, Sep 12, 2012 at 4:14 PM, Navin Gupta navin.nit...@gmail.com wrote:
int temp = {[1(j-+1)]i-1};
Here temp is a number with all the bits set between positions i j
in the first loop the value of k shuld vary from 0 to j-i.
On Oct 1, 7:26 am, rahul sharma rahul23111...@gmail.com wrote:
You are given two 32-bit numbers, N and M, and two bit positions, i and j.
Write a method to set all bits between i and j in N equal to M (e.g., M
becomes a substring of N
yeah u r ryt.
On Sun, Oct 2, 2011 at 4:20 PM, ravi ojha rbojha...@gmail.com wrote:
in the first loop the value of k shuld vary from 0 to j-i.
On Oct 1, 7:26 am, rahul sharma rahul23111...@gmail.com wrote:
You are given two 32-bit numbers, N and M, and two bit positions, i and
j.
can u tell in this we have to set i and j also or only between elements
say if i=2 and j=6
then
whether we should set bit no 2,3,4,5,6,
or 3,4,5
acc. to me its 2,3,4,5,6,
and ur logic also give that answer
plz tell??
On Sun, Oct 2, 2011 at 4:38 PM, rahul sharma
Replace 0 by -1 and make a[i] as sum of all a[j] j=i Now u need
to find the subarray with sum 0
For this u can use array of size 2n denoting -n to n
Now at sum u can update array of 2n size with the index just found
corresponding to that sum
Overall complexity O(n)
Regards
Replace 0 by -1 and make a[i] as sum of all a[j] j=i Now u need
to find the subarray with sum 0
For this u can use array of size 2n denoting -n to n
Now at sum u can update array of 2n size with the index just found
corresponding to that sum
Overall complexity O(n)
Regards
make a running sum with -1 instead of 0 keep an array of the running
sum.in the array find out the indexes with with equal sum at farthest
distance...those two will be the bouding points of maximum subsesequence..
On Sun, Jan 9, 2011 at 10:19 PM, bittu shashank7andr...@gmail.com wrote:
i
i think its DP Problemstill thinking on the soultion..
@ankur..ur approach nearly matches to mine..what i thought..but we
need actual solution..
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@ Saurabh XOR method will also work under the assumption that array 2 will
contain the same elements as array 1 except one element.
On Fri, Oct 22, 2010 at 9:01 PM, Saurabh Koar saurabhkoar...@gmail.comwrote:
@Mohit: Rajan clearly sais that array 2 contains all the elements of array1
+ 1 extra
@rajan
array 1 - {2,2}
array 2 - { 4,4,1}
according 2 you .. unique is {(4+4+1)-(2+2)}=5 ? but it is not...
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To
@Mohit: Rajan clearly sais that array 2 contains all the elements of array1
+ 1 extra element..Your example doesn't do so...By the way the method
suhhested by Rajan is not universal.It is not necessary that array 2 will
contain the same elements as array 1...XOR method will be the best...
--
You
XOR all of the elements of the array. The duplicated elements cancel
each other out, and the result is the unduplicated element.
Dave
On Oct 21, 9:05 am, bittu shashank7andr...@gmail.com wrote:
You have an array consisting of 2n+1 elements, n elements in it are
married, i.e they occur twice in
I think that you are saying that the second array contains all of the
elements in the first array, plus one additional element. If this is
the proper interpretation, then just XOR all of the elements of both
arrays and the result is the additional element.
Dave
On Oct 21, 9:12 am, bittu
@Dave - There could be another good solution instead of XOR.
If below interpretation of the problem is correct,
Array1 - contains n elements ( order is irrelevent)
Array2 - contains all n elements of Array1 ( order is irrelevent) + 1 extra
element which is unique from all n elements of Array1.
The answer would be:
(log1+1) + (log2+1) + (log3+1) + (log4+1) + ... + (log(n-1)+1)
which is equal to:
(log1+log2+log3+...+log(n-1)) + (n-1)
== *log((n-1)!) + (n-1)*
where, log everywhere is assumed to be in base 2
*This according to me will be the final answer!*
*
*
*Cheers*
*Nikhil Jindal
*
On
n*ceil(log_2n)
On Sep 24, 9:23 am, Krunal Modi krunalam...@gmail.com wrote:
But, how was it derived ? :(
What is the intuition behind ? :( :(
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@Dave sorry i didnt see k n (thought it was k=n)
The intuition i guess would be at every powers of 2 it increases by 1 i.e
1=0
2=1
3=1+1=2
4=2+2=4 see the increase of 2 here
5=4+2=6
6=6+2=8
7=8+2=10
8=10+3=13 ..see the increase of 3 here
i guess we can work on from here
On Fri, Sep
what's the datatype of j? mathematically speaking, the while loop is
infinite for every j0...
On Sep 23, 6:19 am, Krunal Modi krunalam...@gmail.com wrote:
for(k=1 ; kn ; k++){
j=k;
while(j0){
j=j/2;
}
}
How many times while loop gets executed (for any n) ?
I don't want
@Krunal: N = n * ceiling(log_2(n)) - 2^ceiling(log_2(n)) + 1,
where a^b is a to the power b.
Dave
On Sep 23, 8:19 am, Krunal Modi krunalam...@gmail.com wrote:
for(k=1 ; kn ; k++){
j=k;
while(j0){
j=j/2;
}
}
How many times while loop gets executed (for any n) ?
I don't want
@ Dave
can u explain ur answer...plz..
On Thu, Sep 23, 2010 at 8:55 AM, Dave dave_and_da...@juno.com wrote:
@Krunal: N = n * ceiling(log_2(n)) - 2^ceiling(log_2(n)) + 1,
where a^b is a to the power b.
Dave
On Sep 23, 8:19 am, Krunal Modi krunalam...@gmail.com wrote:
for(k=1 ;
@Apoorve : All are integer int.
@Dave: Can you explain how u arrived at this equation ?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send
How did I arrive at this equation? I entered the first few terms of
the sequence, 0,1,3,5,8,11,14,17, into the On-Line Encyclopedia of
Integer Sequences, at http://www.research.att.com/~njas/sequences/,
and read the Formula section of the result. It is amazing what you
can find on the internet if
But, how was it derived ? :(
What is the intuition behind ? :( :(
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
check this code . if it works correctly ?
reverse the ans and you will find the no converted in target base.(ignore
extra 0's)
#include stdio.h
#include stdlib.h
#include string.h
#define MAX 10
int main()
{
int i;
int b1,b2;
char no1[MAX] = ,no2[MAX] = ;
int *result = (int *) calloc
@above
Can't you please explain a bit?
On Aug 29, 10:15 am, rahul patil rahul.deshmukhpa...@gmail.com
wrote:
Check out my solution. Hope u are looking for this,
Take a no 136 (base7 = 76 decimal ) convert to base 5 (ans shld be
301)
start from left side 1*7^2= 49/5^2 = 1 (rem 24)
@Rahul : I know that u are using table of base b2 in base b1 and then
dividing the number using the table ...but the real problem is to code
it
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
Check out my solution. Hope u are looking for this,
Take a no 136 (base7 = 76 decimal ) convert to base 5 (ans shld be
301)
start from left side 1*7^2= 49/5^2 = 1 (rem 24)-
|
^
10
3*7 + 24 = 45 /5 = 19 (rem 0)
can u provide solution of base conversion problem discussed abpve
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
@ Rahul in Tejus Can u provide solution base conversion problem
discussed above
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
I would again say that you don't have to use any intermediate base
while converting.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
Since any modern computer is going to do all its operations in base 2,
this is impossible. You have to allow the base that the computer uses
for fundamental arithmetic.
On Aug 18, 8:33 am, luckyzoner luckyzo...@gmail.com wrote:
I would again say that you don't have to use any intermediate base
35 matches
Mail list logo