Re: [algogeeks] reverse a string efficiently

2012-11-26 Thread shady
oh, understood, i thought it takes constant time suppose if it takes, then is there any benefit of this recursion compared to reverse(str) = str[lastcharacter] + reverse(str(0, last-1)) it will reduce the recursion depth right ? No gain on time complexity though a small correction, btw, T(n)

Re: [algogeeks] reverse a string efficiently

2012-11-26 Thread bharat b
it is same as merge sort working procedure as atul said. On Tue, Nov 27, 2012 at 12:48 PM, atul anand wrote: > considering '+' , here will take Cn time . Here '+' is for concatenate , > now this concatenation taking place in constant time?? , i dont think > so..internally it will be adding elemen

Re: [algogeeks] reverse a string efficiently

2012-11-26 Thread atul anand
considering '+' , here will take Cn time . Here '+' is for concatenate , now this concatenation taking place in constant time?? , i dont think so..internally it will be adding elements to new m/m space and for that it need to traverse each character...so it will take cn time. so T(n) =T(n/2) + cn =

Re: [algogeeks] Re: Largest contigious subarray with average greather than k

2012-11-26 Thread Rahul Kumar Patle
hi @all: i am little bit confused on the discussion going here on this thread.. largest subset sum problem in computer science is NP complete as followed http://en.wikipedia.org/wiki/Subset_sum_problem also in book written by CLRS in chapter 35.5 i have found that "The decision problem ask whether

[algogeeks] Re: fastest sequential access

2012-11-26 Thread Don
This is an implementation-specific issue, and will vary between languages and container libraries. Some responders have mentioned that vectors are synced, which makes them slower. That's true in Java. Not true in C++. Certainly not true in C. The only way to know for sure which is faster is to run

Re: [algogeeks] Pthread and Semaphore

2012-11-26 Thread Jagannath Prasad Das
Thanks all for the response. I thought of constructing a conditional wait using semaphores as follows: //global flag = 0. void *text(void *arg) { int n = *(int*)arg; while(flag != n) { sem_wait(&mutex); internal_flag = 1; } if(internal_flag) sem_post(&mutex); ..