Re: [algogeeks] Re: Number Theory (Power of 3 )

2011-12-10 Thread tech coder
u people absolutely correct that log operation take much time , i just given an approach On Sat, Dec 10, 2011 at 7:25 AM, Dave wrote: > @Gaurav: Even though this is O(log n), it is bound to be slow, since > it would use division and modulus are among the slowest operations on > modern computers,

Re: [algogeeks] Re: Number Theory (Power of 3 )

2011-12-07 Thread saurabh singh
Originaly problem rules out the use of log.Moreover log (or any floating point operations) take lot of hardware time as they are emulated on the floating point environment on most machines.Thirdly precision problem for higher values of n may cause your solution to give wron g answers,,, On Wed, De

Re: [algogeeks] Re: Number Theory (Power of 3 )

2011-12-07 Thread tech coder
what about this log(base 3 n) is of integral type then n is a power of 3 On Mon, Dec 5, 2011 at 11:36 PM, Dave wrote: > @Carl: You can generate the constants the first time the procedure is > called. There is no need to do them every time. So the first call > would be O(wordsize) but subsequ

Re: [algogeeks] Re: Number Theory (Power of 3 )

2011-12-05 Thread Carl Barton
Sorry, I was being a bit vague. I meant what would the time complexity be then? As I understand your Constant time is Dependant on the constant pre computation you do, which is no longer the case when you generalise On 5 December 2011 16:14, Dave wrote: > @Carl: Of course. For any given word siz

Re: [algogeeks] Re: Number Theory (Power of 3 )

2011-12-05 Thread Carl Barton
Ah I see, in which case could you not generalise your solution for all integers? By taking into account the size of words on the computer for example? On 5 December 2011 15:09, Dave wrote: > @Carl: Yes, as coded, my algorithm is for 32-bit integers. But the > original poster asked for a soluti

Re: [algogeeks] Re: Number Theory (Power of 3 )

2011-12-05 Thread Carl Barton
@Dave Yours only works for a certain subset of all possible powers or 3 doesn't it? So WgpShashank's would be more general? On 5 December 2011 14:30, Dave wrote: > @WgpShashank: Yours is an O(log n) solution. Mine is O(1). > > Dave > > On Dec 5, 6:21 am, WgpShashank wrote: > > @SAMMM have a lo

Re: [algogeeks] Re: Number theory

2011-08-17 Thread Puneet Goyal
+1 nitin there must be n-1 dividers On Wed, Aug 17, 2011 at 4:15 PM, Puneet Goyal wrote: > I think it should be 2^n -1 > > Explanation > We can visualize it as n balls are placed and we have to place some > dividers (max=n) in betweek to divide them into groups. > > If we choose no divider its nC

Re: [algogeeks] Re: Number theory

2011-08-17 Thread Nitin Nizhawan
@Puneet, you are right but we can have only n-1 dividers. On Wed, Aug 17, 2011 at 4:15 PM, Puneet Goyal wrote: > I think it should be 2^n -1 > > Explanation > We can visualize it as n balls are placed and we have to place some > dividers (max=n) in betweek to divide them into groups. > > If we ch

Re: [algogeeks] Re: Number theory

2011-08-17 Thread Puneet Goyal
I think it should be 2^n -1 Explanation We can visualize it as n balls are placed and we have to place some dividers (max=n) in betweek to divide them into groups. If we choose no divider its nC0 , but we dont have to include it With 1 divider its nC1 and so on.. So the total no. of ways will be

Re: [algogeeks] Re: Number theory

2011-08-17 Thread Rohit Srivastava
+1 to nitin On Wed, Aug 17, 2011 at 2:48 PM, Vijay Kansal wrote: > my bad 2^(n-1)... > > On Aug 17, 2:17 pm, Vijay Kansal wrote: > > @nitin it must be 2^n i think > > > > On Aug 17, 3:48 am, Bharat Kul Ratan wrote: > > > > > > > > > > > > > > > > > It might be useful: > http://www.artofproblems