Re: [algogeeks] [brain teaser ] A Riddle

2011-06-22 Thread Yameni Dhankar
was he driving an ambulance? On Wed, Jun 22, 2011 at 12:33 PM, Lavesh Rawat lavesh.ra...@gmail.comwrote: *A Riddle ** * * * ** *A bus driver was heading down a street in Delhi. He went right past a stop sign without stopping, he turned left where there was a 'no left turn' sign and he

Re: [algogeeks] [brain teaser ] A Riddle

2011-06-22 Thread Vishal Thanki
was he driving a bus or tram? On Wed, Jun 22, 2011 at 12:36 PM, Yameni Dhankar yamenid...@gmail.com wrote: was he driving an ambulance? On Wed, Jun 22, 2011 at 12:33 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: A Riddle A bus driver was heading down a street in Delhi. He went right past

Re: [algogeeks] [brain teaser ] A Riddle

2011-06-22 Thread Shachindra A C
he was walking On Wed, Jun 22, 2011 at 12:38 PM, Vishal Thanki vishaltha...@gmail.comwrote: was he driving a bus or tram? On Wed, Jun 22, 2011 at 12:36 PM, Yameni Dhankar yamenid...@gmail.com wrote: was he driving an ambulance? On Wed, Jun 22, 2011 at 12:33 PM, Lavesh Rawat

Re: [algogeeks] OS

2011-06-22 Thread Shachindra A C
last year's gate question? On Tue, Jun 21, 2011 at 11:32 PM, Akshata Sharma akshatasharm...@gmail.comwrote: But, the OS maintains a separate PC (program counter ),stack and A CPU register state for a thread . So option A I am not sure is correct, it says ONLY.. scheduling and accounting

Re: [algogeeks] Re: google interview c testing

2011-06-22 Thread Anika Jain
bt even in c++ if we do int a[5]; a=new int[0]; its error.. On Sun, Jun 19, 2011 at 12:59 PM, kumar vr kumarg...@gmail.com wrote: how to free memory allocated to an array with new function? A. a = new int[0]; Assuming integer Data. On Sat, Jun 18,

[algogeeks] Google Question

2011-06-22 Thread chirag ahuja
Given an array of size n wherein elements keep on increasing monotonically upto a certain location after which they keep on decreasing monotonically, then again keep on increasing, then decreasing again and so on. Sort the array in O(n) and O(1). I didn't understand the question, any array of n

[algogeeks] Re: strings

2011-06-22 Thread ross
@Harshal, Even if you use a buffer of size 256 it is still O(1), because 256 is a constant invariant of n... Ur solution is correct! On Jun 22, 10:24 am, Harshal hc4...@gmail.com wrote: ignore above solution. My bad, did'nt see O(1) space constraint!! On Wed, Jun 22, 2011 at 10:53 AM,

[algogeeks] Re: sort the array

2011-06-22 Thread ross
@himanshu: I dont think, the approach works, in present form. in place merge sort or insertion sort is fine. Test with, 12 13 19 16 and 0 20 10 14 as 2 parts of the array. On Jun 22, 8:42 am, Sriganesh Krishnan 2448...@gmail.com wrote: ya...we can do it in O(n) n time!!! nice question! On

Re: [algogeeks] Google Question

2011-06-22 Thread Piyush Sinha
This question has been discussed over here once...It was concluded that this can be solved in O(n) if we know there is a fixed range up to which the elements keep on increasing and decreasing..for example in an array of 12 elements, we know 3 elements keep on increasing monotonically, then 3

Re: [algogeeks] Re: strings

2011-06-22 Thread Harshal
@ross: ya, don't know what i was thinking.!! On Wed, Jun 22, 2011 at 2:33 PM, ross jagadish1...@gmail.com wrote: @Harshal, Even if you use a buffer of size 256 it is still O(1), because 256 is a constant invariant of n... Ur solution is correct! On Jun 22, 10:24 am, Harshal

Re: [algogeeks] Binary Tree

2011-06-22 Thread Anantha Krishnan
I modified Sunny's code to get Node X and Node Y. http://ideone.com/YF9qi Can we do better than this? Thanks Regards, Anantha Krishnan On Wed, Jun 22, 2011 at 11:11 AM, oppilas . jatka.oppimi...@gmail.comwrote: Sunny, Can but can we modify this code to get the *node X and node Y*?. On

Re: [algogeeks] Re: strings

2011-06-22 Thread saurabh singh
Without the ascii count table as harshal has used above,is it possible to do the problem in o(n) time? On Wed, Jun 22, 2011 at 2:57 PM, Harshal hc4...@gmail.com wrote: @ross: ya, don't know what i was thinking.!! On Wed, Jun 22, 2011 at 2:33 PM, ross jagadish1...@gmail.com wrote: @Harshal,

Re: [algogeeks] نيك عربي وصراخ من الطيز بقوه

2011-06-22 Thread Naveen Kumar
ban him moderators... 2011/6/22 asxsa asxsa 3.asxs...@gmail.com http://4.bp.blogspot.com/-PcXVe1X1NdY/TftHfQSjwyI/Abc/3Z3MHGcxKv0/s1600/thumbs20110616223014.jpg [image: http://i20.servimg.com/u/f20/09/00/39/91/010.png] [image: http://i20.servimg.com/u/f20/09/00/39/91/010.gif]

Re: [algogeeks] نيك عربي وصراخ من الطيز بقوه

2011-06-22 Thread oppilas .
+1 2011/6/22 Naveen Kumar naveenkumarve...@gmail.com ban him moderators... 2011/6/22 asxsa asxsa 3.asxs...@gmail.com http://4.bp.blogspot.com/-PcXVe1X1NdY/TftHfQSjwyI/Abc/3Z3MHGcxKv0/s1600/thumbs20110616223014.jpg [image: http://i20.servimg.com/u/f20/09/00/39/91/010.png]

Re: [algogeeks] Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread radha krishnan
@balaji : i think u understand the question in wrong way !! The solution is to use Manchar Algorithm !! But thats hard to implement On Wed, Jun 22, 2011 at 12:05 AM, Balaji S balaji.ceg...@gmail.com wrote: LCS(string,reverse(string)) ?? but this is not O(n) ryt.. -- With Regards,

[algogeeks] Re: ReadyForZero Programming Challenge

2011-06-22 Thread Tundebabzy
Thanks so much Wladmir. This algorithm will assume that the second character in the string will be the root of the binary tree which could be misleading. The root might be the last character in the string. The only thing that seems to be universally correct is that the first character in the

[algogeeks] Re: Google Question

2011-06-22 Thread Dumanshu
@Piyush: could u plz post the link to the same? On Jun 22, 2:15 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: This question has been discussed over here once...It was concluded that this can be solved in O(n) if we know there is a fixed range up to which the elements keep on increasing and

Re: [algogeeks] نيك عربي وصراخ من الطيز بقوه

2011-06-22 Thread karan sachan
+1...i have already reported him SPAM!! 2011/6/22 oppilas . jatka.oppimi...@gmail.com +1 2011/6/22 Naveen Kumar naveenkumarve...@gmail.com ban him moderators... 2011/6/22 asxsa asxsa 3.asxs...@gmail.com

[algogeeks] Find the error..

2011-06-22 Thread Balaji S
What is the wrong in this program main() { char *p,*q; p=(char *)malloc(25); q=(char*) malloc(25); strcpy(p,INDIA ); strcpy(q,hyd); strcat(p,q); printf(%s,p); } -- With Regards, Balaji.S -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Find the error..

2011-06-22 Thread PRITPAL SINGH
What do you expect it to give ? On Wed, Jun 22, 2011 at 4:25 PM, Balaji S balaji.ceg...@gmail.com wrote: What is the wrong in this program main() { char *p,*q; p=(char *)malloc(25); q=(char*) malloc(25); strcpy(p,INDIA ); strcpy(q,hyd); strcat(p,q); printf(%s,p); } -- With

Re: [algogeeks] Find the error..

2011-06-22 Thread PRITPAL SINGH
http://www.ideone.com/pubwV On Wed, Jun 22, 2011 at 4:30 PM, PRITPAL SINGH pritpal2...@gmail.comwrote: What do you expect it to give ? On Wed, Jun 22, 2011 at 4:25 PM, Balaji S balaji.ceg...@gmail.com wrote: What is the wrong in this program main() { char *p,*q; p=(char *)malloc(25);

Re: [algogeeks] Find the error..

2011-06-22 Thread Shachindra A C
the only thing wrong about the program is the memory leak :p On Wed, Jun 22, 2011 at 4:30 PM, PRITPAL SINGH pritpal2...@gmail.comwrote: What do you expect it to give ? On Wed, Jun 22, 2011 at 4:25 PM, Balaji S balaji.ceg...@gmail.com wrote: What is the wrong in this program main() {

[algogeeks] online judge for parallel programming

2011-06-22 Thread titus_n
Is there an online judge where the solution to a problem has to run on multiple cores? Would such a judge be valuable in training folks to write parallel programs? Or is this idea just silly, because the parallel solution would be nearly the same to the single core one. It would just use some

Re: [algogeeks] Re: sort the array

2011-06-22 Thread Algoose chase
Reverse the 2nd part of the Array so that they are sorted in descending order. Then apply bitonic sort On Wed, Jun 22, 2011 at 2:34 PM, ross jagadish1...@gmail.com wrote: @himanshu: I dont think, the approach works, in present form. in place merge sort or insertion sort is fine. Test with,

[algogeeks] online judge for parallel programming

2011-06-22 Thread Nicolae Titus
Is there an online judge where the solution to a problem has to run on multiple cores? Would such a judge be valuable in training folks to write parallel programs? Or is this idea just silly, because the parallel solution would be nearly the same to the single core one. It would just use some

Re: [algogeeks] OS

2011-06-22 Thread sachin sharma
@Rahul Threads within a process share the same virtual memory space but each has a separate stack, and possibly thread-local storage. this thread local storage is register and other private data. They are *lightweight* because a context switch is simply a case of switching the stack pointer and

[algogeeks] Explain this.....

2011-06-22 Thread udit sharma
#includestdio.h int main() { void print(int *,int *,int *,int *,int *); static int arr[]={97,98,99,100,101,102,103,104}; int *ptr=arr+1; print(++ptr,ptr--,ptr,ptr++,++ptr); return 0; } void print(int *a,int *b,int *c,int *d,int *e) { printf(%d\t%d\t%d\t%d\t%d\n,*a,*b,*c,*d,*e); } Why the output

Re: [algogeeks] Find the error..

2011-06-22 Thread Balaji S
@pritpal : Refer ques 5 at http://www.youthrocker.com/2011/06/interview-questions-amazon-placement.html @shachindra : wats tat :-o -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Find the error..

2011-06-22 Thread PRITPAL SINGH
@balaji I think memory leak is the only problem with the code. rest is fine On Wed, Jun 22, 2011 at 6:03 PM, Balaji S balaji.ceg...@gmail.com wrote: @pritpal : Refer ques 5 at http://www.youthrocker.com/2011/06/interview-questions-amazon-placement.html @shachindra : wats tat :-o -- You

Re: [algogeeks] Find the error..

2011-06-22 Thread Shachindra A C
@balaji, the memory allocated from the heap using malloc needs to be released before termination of the program. there should be two additional statements as follows: free(p); free(q); On Wed, Jun 22, 2011 at 6:09 PM, PRITPAL SINGH pritpal2...@gmail.comwrote: @balaji I think memory leak is

Re: [algogeeks] Find the error..

2011-06-22 Thread Vishal Thanki
memory leak and memory allocation check, make sure malloc return non-null. On Wed, Jun 22, 2011 at 7:04 PM, Shachindra A C sachindr...@gmail.com wrote: @balaji, the memory allocated from the heap using malloc needs to be released before termination of the program. there should be two additional

Re: [algogeeks] Interview Question: Puzzle: Probability

2011-06-22 Thread Vishal Jain
Navneet, Your answer is correct, it would have been great if you could have explained it for others. I myself took good time to understand it... Here is the answer http://exploreriddles.blogspot.com/2011/06/interview-questions-puzzle.html To maximize the chances of retrieving Red Ball, it is

Re: [algogeeks] Find the error..

2011-06-22 Thread ankit sambyal
@Balaji : the code given by u compiles and runs successfully in gcc compiler and gives the correct answer i.e. INDIAhyd . What's the problem ?? @Shachindra A C : Which memory leak are you talking about ?? The memory allocated from the heap using malloc need not be released before termination of

Re: [algogeeks] Find the error..

2011-06-22 Thread ankit sambyal
@Vishal : Ya this seems to be correct.. On Wed, Jun 22, 2011 at 7:05 AM, ankit sambyal ankitsamb...@gmail.com wrote: @Balaji : the code given by u compiles and runs successfully in gcc compiler and gives the correct answer i.e.  INDIAhyd . What's the problem ?? @Shachindra A C : Which memory

Re: [algogeeks] Explain this.....

2011-06-22 Thread Piyush Sinha
r u sure the last output is also 100..for me its coming 99 On 6/22/11, udit sharma sharmaudit...@gmail.com wrote: #includestdio.h int main() { void print(int *,int *,int *,int *,int *); static int arr[]={97,98,99,100,101,102,103,104}; int *ptr=arr+1; print(++ptr,ptr--,ptr,ptr++,++ptr);

Re: [algogeeks] Find the error..

2011-06-22 Thread Shachindra A C
As vishal pointed out, checking the return val is missing and it is the programmer's responsibility to free up the memory which he has requested for... On Wed, Jun 22, 2011 at 7:37 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Vishal : Ya this seems to be correct.. On Wed, Jun 22, 2011 at

Re: [algogeeks] Explain this.....

2011-06-22 Thread oppilas .
Yes, for me also it's coming out 99 If I do it orally but on compiling it's coming 100. http://codepad.org/KKLEXY45 On Wed, Jun 22, 2011 at 7:39 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: r u sure the last output is also 100..for me its coming 99 On 6/22/11, udit sharma

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread SVIX
couldn't we just collect all the letters that occur more than twice and play them back even number of times symmetrically? and if there are more letters left, we can put one of them in the center... linear time need additional memory for some kind of hashing On Jun 21, 11:31 am, Swathi

Re: [algogeeks] Explain this.....

2011-06-22 Thread Piyush Sinha
the arguments are passed from right to left in a function... initially ptr is pointing to location of 98 (i =1) the last argument ++ptr makes it point to 99 therefore output of *e = 99 the second last argument passes pointer to 99 only and then increments its location to i=3 i.e 100...therefore

Re: [algogeeks] Explain this.....

2011-06-22 Thread Piyush Sinha
I am using Dev C++ its showing last output as 99 only On 6/22/11, oppilas . jatka.oppimi...@gmail.com wrote: Yes, that I know, but why last argument is printing 100 instead of 99? On Wed, Jun 22, 2011 at 7:50 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: the arguments are passed from

Re: [algogeeks] Re: sort the array

2011-06-22 Thread Navneet Gupta
Let the array elements be 2,3,5,10 1,4,8,12. Have two index variables m and n. Intially m will point to 2 and n to 1. 1. Compare the elements in m and n. 2. If elem[m] elem[n] swap, increment n 3. else increment m and go to step 1. 4. end if m becomes the starting value of n or n reaches end

Re: [algogeeks] Re: sort the array

2011-06-22 Thread oppilas .
On Wed, Jun 22, 2011 at 8:38 PM, oppilas . jatka.oppimi...@gmail.comwrote: On Wed, Jun 22, 2011 at 8:20 PM, Navneet Gupta navneetn...@gmail.comwrote: Let the array elements be 2,3,5,10 1,4,8,12. Have two index variables m and n. Intially m will point to 2 and n to 1. 1. Compare the

[algogeeks] Re: Explain this.....

2011-06-22 Thread RITESH SRIVASTAV
In any function call , the comma operator used is not a sequence point so the order of evaluation of the arguments sent to the function is not defined .That is why it is giving different output on different compilers. On Jun 22, 7:29 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: I am using

Re: [algogeeks] Re: Explain this.....

2011-06-22 Thread udit sharma
May be it is compiler dependent.. :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For

Re: [algogeeks] Re: Explain this.....

2011-06-22 Thread rajeev bharshetty
First the values are calculated from right to left and then the result is printed from left to right. So the last output is 100 in gcc 4.0 compiler. The ptr pointer is calculated initially and then printed. Try first calculating from right to left... On Wed, Jun 22, 2011 at 9:19 PM, udit sharma

Re: [algogeeks] Re: strings

2011-06-22 Thread DK
No. This is equivalent to a sort with comparisons based on index of first occurrence in the input string. Any comparative algorithm is O(n log n) and a non comparative algorithm can be O(n) only by using counting or radix sorting etc. -- DK http://twitter.com/divyekapoor http://www.divye.in

Re: [algogeeks] Re: strings

2011-06-22 Thread DK
No. This is equivalent to a sort with comparisons based on index of first occurrence in the input string. Any comparative algorithm is O(n log n) and a non comparative algorithm can be O(n) only by using counting or radix sorting etc. -- DK http://twitter.com/divyekapoor http://www.divye.in

[algogeeks] Re: sort the array

2011-06-22 Thread ankit mehta
In step 2 it should me m++ instead of n++ and similarly in step 3 n+ +. But still I dont think it will work if we carry out these iterations on this particular array. It will return , what I think: 1 2 3 5 10 4 8 12. Please correct me if I am wrong. On Jun 22, 7:50 pm, Navneet Gupta

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sanjay ahuja
Suffix tree can solve longest common substring problem in o(n) and longest palindrome in string S is nothing but longest common substring between string s and its reverse. On Wed, Jun 22, 2011 at 9:31 PM, ankit mehta mehta.bond...@gmail.com wrote: You dont have to create longest palindrome,

Re: [algogeeks] Re: sort the array

2011-06-22 Thread Ankit Agarwal
This problem can also be done by using Merging function as in the merge sort. 1. Copy the sorted elements of the first half in one array (arr L) and second half in another (arr R). Original array N. 2. count vary from 1 to n. if (L[i] R[j] ) { N[count] = L[i], i++} else { N[count] = R[j]

Re: [algogeeks] Re: sort the array

2011-06-22 Thread Apoorve Mohan
@ankit: we need an inplace algorithm :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread ankit mehta
Consider string: abcdecba Reverse of above string: abcedcba Longest common substring: abc and cba : Both not Palindromes! On Jun 22, 9:29 pm, sanjay ahuja sanjayahuja.i...@gmail.com wrote: Suffix tree can solve longest common substring problem in o(n) and longest palindrome in string S is

[algogeeks] Re: sort the array

2011-06-22 Thread ankit mehta
Yes thats what I am saying that algorithm presented by Mr. Navneet wont work. On Jun 22, 9:40 pm, Apoorve Mohan apoorvemo...@gmail.com wrote: @ankit: we need an inplace algorithm :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] Re: spoj problem chairs

2011-06-22 Thread VIHARRI
@saurabh : The answer suggested by you is for not all together... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
LCS is abcdcba or abcecba not abc or cba On Wed, Jun 22, 2011 at 10:15 PM, ankit mehta mehta.bond...@gmail.comwrote: Consider string: abcdecba Reverse of above string: abcedcba Longest common substring: abc and cba : Both not Palindromes! On Jun 22, 9:29 pm, sanjay ahuja

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread varun gupta
Does the question mean non-continuous substring? I think it should be continuous substring which is palindrome with in the given string. LCS wouldn't solve problem in this case. On Wed, Jun 22, 2011 at 10:29 PM, sunny agrawal sunny816.i...@gmail.comwrote: LCS is abcdcba or abcecba not abc or

[algogeeks]

2011-06-22 Thread Subhransu
Could anyone help me getting these books : 1) Sun Certified Web Component Developer Study Guide (Exams 310-081 310-082) (Oracle Press) by David Bridgewater 2) Sun Certified Business Component Developer CX-310-091 Exam Certification Exam Preparation Course in a Book for Passing the SCBCD Exam -

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
LCS stands for Longest Common Substring -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks]

2011-06-22 Thread rajeev bharshetty
Try www.warez-bb.org for ebooks On Wed, Jun 22, 2011 at 10:45 PM, Subhransu subhransu.panigr...@gmail.comwrote: Could anyone help me getting these books : 1) Sun Certified Web Component Developer Study Guide (Exams 310-081 310-082) (Oracle Press) by David Bridgewater 2) Sun Certified

[algogeeks] Binary Tree Diameter

2011-06-22 Thread Anantha Krishnan
Hi All, I have written code for finding diameter of a binary tree here http://ideone.com/WHg9t Is it correct? Do I need to make any changes there? Thanks Regards Anantha Krishnan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread varun gupta
That is what ankit said. Consider string: abcdecba Reverse of above string: abcedcba Longest common substring: abc and cba : you are calculating longest common *subsequence* not substring. Substring in continuous. On Wed, Jun 22, 2011 at 10:48 PM, sunny agrawal sunny816.i...@gmail.comwrote:

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread SVIX
ah... i misunderstood the question... sorry.. On Jun 22, 12:01 pm, ankit mehta mehta.bond...@gmail.com wrote: You dont have to create longest palindrome, you have to find the longest palindrome. On Jun 22, 7:19 pm, SVIX saivivekh.swaminat...@gmail.com wrote: couldn't we just collect

[algogeeks] O(n) Time is the problem. ..

2011-06-22 Thread RollBack
An array A[1...n] contains all the integers from 0 to n except for one number which is missing. In this problem, we cannot access an entire integer in A with a single opera- tion. The elements of A are represented in binary, and the only operation we can use to access them is “fetch the jth bit of

Re: [algogeeks] Re: strings

2011-06-22 Thread snehi jain
what if we create a binary tree with root as the first element of the string and if the next character is equal then place it to left else place it to right. Similar comparison will be done while inserting all the other nodes too . after that if InOrder traversal is performed.. it would give us

Re: [algogeeks] Re: strings

2011-06-22 Thread oppilas .
No, it will not work. We don't have to print all the characters in sorted order. On Thu, Jun 23, 2011 at 12:19 AM, snehi jain snehijai...@gmail.com wrote: what if we create a binary tree with root as the first element of the string and if the next character is equal then place it to left else

Re: [algogeeks] Re: strings

2011-06-22 Thread snehi jain
how come its printing in sorted ... i didn't get it... On Thu, Jun 23, 2011 at 12:27 AM, oppilas . jatka.oppimi...@gmail.comwrote: No, it will not work. We don't have to print all the characters in sorted order. On Thu, Jun 23, 2011 at 12:19 AM, snehi jain snehijai...@gmail.comwrote: what

Fwd: [algogeeks] Re: strings

2011-06-22 Thread oppilas .
May be I didn't understood your logic. According to original question for I/P kapilra O/P --kaapilr.. Now, -what if we create a binary tree with root as the first element of the string and if the next character is equal then place it to left else place it to right. Similar comparison will be

Re: [algogeeks] Re: strings

2011-06-22 Thread snehi jain
the binary tree for the above example will be k(1) \ a(2) / \ (7) a p(3) \ i(4) \ l(5) \

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread sunny agrawal
ohh sorry my mistake LCS stands for Longest Common Subsequence On Wed, Jun 22, 2011 at 11:21 PM, SVIX saivivekh.swaminat...@gmail.comwrote: ah... i misunderstood the question... sorry.. On Jun 22, 12:01 pm, ankit mehta mehta.bond...@gmail.com wrote: You dont have to create longest

Re: [algogeeks] Binary Tree

2011-06-22 Thread Jitendra singh
I think this solution is wrong . Because for the case - 1 5 8 10030010 ans should be 406 But above code gives 124 On 6/22/11, Anantha Krishnan ananthakrishnan@gmail.com wrote: I modified Sunny's code to get Node X and Node Y.

Re: [algogeeks] Binary Tree

2011-06-22 Thread Jitendra singh
Solution should be- each node has three values 1) root_cur 2)cur_fleaf 3)cur_sleaf strcut ret_ele { largest; second_largest } ret_ele solve(node,sum_root_cur) { if(node==rootroot==NULL) { sum_root_cur=0; return; } root_cur=sum_root_cur

Re: [algogeeks] Re: strings

2011-06-22 Thread Rohit Sindhu
@snehi .. your solution does not come upto the O(n) as for n elements of string it will take O(lg n) for each , so a total of O ( n * lg n ) Otherwise a better variation to Solution is taking a count member in each node and incrementing it when another occurrence is made of that character.

Re: [algogeeks] Binary Tree

2011-06-22 Thread sunny agrawal
@Jitendra Both are working fine Which code r u talking about? On Thu, Jun 23, 2011 at 2:19 AM, Jitendra singh jsinghrath...@gmail.comwrote: Solution should be- each node has three values 1) root_cur 2)cur_fleaf 3)cur_sleaf strcut ret_ele { largest; second_largest } ret_ele

[algogeeks] spoj shlights

2011-06-22 Thread kartik sachan
QUESTION LINK IS http://www.spoj.pl/problems/SHLIGHTS/ MY CODE IS GIVEN BELOW ITS IS GIVING TLEPLZZ HELP ME OUT # includecstdio # includecstring int main() { int t; char a[17]; scanf(%d,t); int i,j,k; while(t--) { int count=0; int flag=0,flag1=0;

Re: [algogeeks] Re: strings

2011-06-22 Thread varun pahwa
@Harshal: I think ur code will print the input string in a sorted order. @Snehi: Ur tree will never be balanced. and in worst case scenario there will be only right child.so in that case generation of binary tree may go upto O(n*n). P.S.: correct me if i am wrong. On Wed, Jun 22, 2011 at 1:50 PM,

Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-22 Thread abhishek agrawal
http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ This algo runs in Linear time. On Thu, Jun 23, 2011 at 1:23 AM, sunny agrawal sunny816.i...@gmail.comwrote: ohh sorry my mistake LCS stands for Longest Common Subsequence On Wed, Jun 22, 2011 at 11:21

Re: [algogeeks] Binary Tree

2011-06-22 Thread Anantha Krishnan
@Jitendra I guess your tree construction is wrong. You can verify by replacing the Construct function with this: *void Construct() {* *Node* d = new Node(100);* *Node* e = new Node(300);* *Node* g = new Node(10);* *Node* b = new Node(5, d, e);* *Node* c =

Re: [algogeeks] strings

2011-06-22 Thread Nishant Mittal
@Harshal... ur solution is nt correct.it is nt printing the characters in order as given in i/p... i know the solution using auxiliary array and using an extra character array to hold the o/p string but if any1 knows inplace solution then plz rply... On 6/22/11, Harshal hc4...@gmail.com wrote:

[algogeeks] Re: ReadyForZero Programming Challenge

2011-06-22 Thread VJ
what if we assume that it's a complete binary tree with height 10(2^10-1 = 1023) ?? On Jun 22, 3:05 pm, Tundebabzy tundeba...@gmail.com wrote: Thanks so much Wladmir. This algorithm will assume that the second character in the string will be the root of the binary tree which could be

[algogeeks] Question on Combination

2011-06-22 Thread ross
Given an array and a sum S output all combinations of elements that sum to S. eg: 1 2 3 sum = 3 1+1+1, 2+1 3 I came up with the foll algorithm, but it outputs 2+1 and 1+2 again. (does not handle repetitions) printcombinations(int a[],int sum,int level) { if(sum==0) { print array} else if (sum0)

[algogeeks] string matching

2011-06-22 Thread prateek gupta
In naive string matching how can the knowledge abt. pattern that it has all different characters can be used to accelerate the algorithm to O(n) . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Question on Combination

2011-06-22 Thread Piyush Sinha
pass one more argument to the function *int index* and instead of starting the loop from *i = 0 to N, *make it start from *i = index to N *and then call *printcombinations(a,sum-a[i],level+1,index+1); *I think it will work then... On Thu, Jun 23, 2011 at 10:48 AM, ross

Re: [algogeeks] string matching

2011-06-22 Thread Piyush Sinha
Read KMP algorithm.. On Thu, Jun 23, 2011 at 11:17 AM, prateek gupta prateek00...@gmail.comwrote: In naive string matching how can the knowledge abt. pattern that it has all different characters can be used to accelerate the algorithm to O(n) . -- You received this message because you are

Re: [algogeeks] string matching

2011-06-22 Thread sunny agrawal
last line is *in worst case k=1 only 2*n comparisons will be there hence O(n)* On Thu, Jun 23, 2011 at 11:26 AM, sunny agrawal sunny816.i...@gmail.comwrote: Lets Consider the case of Naive matching in which at some shift s first k characters are matched and next character does not match so

Re: [algogeeks] string matching

2011-06-22 Thread prateek gupta
yup, got it thanks!!! On Thu, Jun 23, 2011 at 11:27 AM, sunny agrawal sunny816.i...@gmail.comwrote: last line is *in worst case k=1 only 2*n comparisons will be there hence O(n)* On Thu, Jun 23, 2011 at 11:26 AM, sunny agrawal sunny816.i...@gmail.comwrote: Lets Consider the case of