[algogeeks] Renaming namespaces c++
Hi all, I went through the following post on Stack overflow: http://stackoverflow.com/questions/6108704/renaming-namespaces but I have questions on the solution given, The question mentions about change of namespace from old to _new::nested for the class because of which any reference to SomeClass in already existing code will need to adjusted without much work. So as mentioned in the question one way is to use namespace old { typedef _new::nested::SomeClass Someclass; } so that any reference to Someclass in the form of old::Someclass obj; or as namespace old { Someclass Obj }; in the CPP file is properly understood. However in the ideone solution given in the first response to this question, the declaration of the variable inside int main() is changed to adjust to this new namespace.I think two here refers to the new namespace and one to the old. Is not this slightly impractical since Someclass class object could be created at multiple places in a huge code base and scoping each object declaration to adjust to the new namesapce is time consuming?That way is not the solution mentioned in the question itself fine since the CPP code where the class is used can be untouched with Someclass automatically now referring to the updated namespace due to the typedef? Am I missing something here? Arun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
[algogeeks] why does this work?
I tried the following on ideone #include stdio.h int main(){ int *temp; printf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(value is %p\n,temp); return 0;} it prints that : value is (nil) which am assuming is NULL if I try to print *temp it gives me segv which I would expect. However if I do something as *temp=5; it does not segv. How does this happen? If it was a NULL pointer it cannot dereference it right? Arun -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.
Re: [algogeeks] Pointers Usage
@atul/shady: why is it that pointer takes 8 bytes ? So the takes a memory location whose value is the address of the element it points to. Why does the pointer value have to take 8 bytes? I am sorry if I am missing something silly here. On Thu, Jan 3, 2013 at 3:11 AM, Debabrata Das debabrata.barunhal...@gmail.com wrote: array would be allocated in stack and stack is very limited compared to heap.If you want temporary data storage go for stack which will be freed from stack once array goes out of scope else heap is preferred. On Thu, Jan 3, 2013 at 1:01 AM, Rahul raikra...@gmail.com wrote: Take a look at the linux kernel . Or VLC player 's source code. You will not ask this question again. -- -- Even the measly pawn draws respect from the powerful king as it has the power to become a queen one day..Respect everyone in life! --
Re: [algogeeks] Re: parameters to non-const and const reference concept-C++
@Lucifer: Thanks a lot for the explanation On Sun, Dec 23, 2012 at 4:51 AM, Lucifer sourabhd2...@gmail.com wrote: @phoenix The reason is not an implication of using references. If u are passing emptyvec() as an argument then the vector returned by emptyvec() is a temp object ( as its not being assigned to a obj var created by the programmer), which means that the user/programmer shouldn't be able to change it. Because temp objects are not under the control or rather can't be explicitly created/handled by the programmer. Hence, it won't allow u to modify the temp object. Now when a temp object is assigned to a const ref, it automatically means that u can use but can't modify it which is expected. But, if its a non-const ref, then that means one can modify a temp object which ideally a programmer doesn't have a control on. On Sunday, 23 December 2012 07:33:48 UTC+5:30, phoenix wrote: Hi, Could someone explain the logic behind the following: Arguments that correspond to non-const reference parameters must be lvalues-that is they must be non-temporary objects. Arguments that are passed by value or bound to a const reference can be any value Suppose a function returns an empty vector vectordouble emptyvec() { vector doublev; return v; } Now calling another function which accepts const reference as a parameter does not error out but function which accepts non-const reference parameter errors when passing emptyvec() to it.Why? I do not understand the concept. This emptyvec() function returns a copy of v to the caller and destroys v which is local to emptyvec(). So why cannot this copy be passed without error as a non-const reference. Why is the behavior different between const and non-const reference.? -- -- Even the measly pawn draws respect from the powerful king as it has the power to become a queen one day..Respect everyone in life! --
[algogeeks] parameters to non-const and const reference concept-C++
Hi, Could someone explain the logic behind the following: Arguments that correspond to non-const reference parameters must be lvalues-that is they must be non-temporary objects. Arguments that are passed by value or bound to a const reference can be any value Suppose a function returns an empty vector vectordouble emptyvec() { vector doublev; return v; } Now calling another function which accepts const reference as a parameter does not error out but function which accepts non-const reference parameter errors when passing emptyvec() to it.Why? I do not understand the concept. This emptyvec() function returns a copy of v to the caller and destroys v which is local to emptyvec(). So why cannot this copy be passed without error as a non-const reference. Why is the behavior different between const and non-const reference.? --
Re: [algogeeks] finding element in array with minimum of comparing
@Dave: Nice solution. Can you clarify why you need to store the first element in a temp variable and put 'elem' in the first position? If elem was already first in array then it makes no difference. If elem was not first but somewhere in between, the loop will break there when coming from behind and size will have the index right? Why do we need to store elem in first position according to your code? On Sun, Oct 7, 2012 at 3:01 PM, Mangal Dev Gupta dev.it...@gmail.comwrote: *@Dave while( arr[--size] != elem );* *Exception will come when it will encounter a[-1]* *i dont know if this loop will ever end... very poor solution i will say * On Sat, Oct 6, 2012 at 10:00 PM, Umer Farooq the.um...@gmail.com wrote: Well actually, I've just gone through Dave's code thoroughly and I believe that his code is most appropriate. Thanks viper11 for providing the explanation. As for my code, I'd like to replace while (i!=j) with while (i j) because != won't work for middle element if the number of elements are odd ... and it also won't work if the number of elements are even. Anyway, thanks Dave for providing us with such a great solution. Please keep posting! :-) And others, thanks for pointing out the issue in my code. On Sat, Oct 6, 2012 at 9:03 PM, Kalidhakani J kanikali...@gmail.comwrote: @umer - what if the element to be searched is at the middle of the array? your code doesn't handles this. check out. On Sat, Oct 6, 2012 at 3:38 AM, icy` vipe...@gmail.com wrote: nice solution, Dave! @Umer -- if the sought ele is first, then Dave's code has it sitting in the variable temp for a little while. Loop will stop when size is 0, since arr[0]==elem. Now he throws temp back into arr[0], which will return index 0 from the last compare line. On Wednesday, October 3, 2012 2:08:56 AM UTC-4, Umer Farooq wrote: @Dave Thanks for pointing that out. But I still can't get what if elem is on first element or it is not present in the array? How is your code going to handle that situation? @Atul, Well yes, In the given question, the number of iterations were 2n. Which I have reduced to n+n/2. On Tue, Oct 2, 2012 at 11:13 PM, atul anand atul.8...@gmail.comwrote: @umer : how no. of comparison are reduced to half by moving both sidesyou have 2 if condition inside, so you are making 2 comparisons at each iteration + n/2 comparison for while loop so number of comparisons are n+n/2 On 10/2/12, Umer Farooq the@gmail.com wrote: why don't we try it from both ends ... something like this: int i = 0; j = size-1; while (i != j) { if (arr[i] == elem) return arr[i]; if (arr[j] == elem) return arr[j]; } this way, we have eliminated half of the comparisons in for loop? What do you guys say? On Tue, Oct 2, 2012 at 12:18 PM, rafi rafiw...@gmail.com wrote: Vikas is right! while (n) is equal to (while n!=0) you have 2n compares! בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas: still there is no improvement, compiler will generate the code to compare with zero here. what you have accomplished is , hide it from human eyes On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote: @atul: still it won't compare 0 th element. Slight modification in your code: n=*sizeof(arr)*; do { if(elem==arr[*--n*]) print found; }while(n); On Mon, Oct 1, 2012 at 9:50 AM, atul anand atul.8...@gmail.com wrote: yes, but there no need of checking outside the loop n=sizeof(arr)-1; do { if(elem==arr[n]) print found; n--; }while(n); On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar algorit...@gmail.comwrote: @atul: keep one more checking outside loop for element at 0 th index. Because when n = 0 the your loop come out from the loop without comparing it. On Mon, Oct 1, 2012 at 8:55 AM, atul anand atul.8...@gmail.comwrote: n=sizeof(arr); n--; while(n) { if(elem=arr[n]) print found; n--; } On Sun, Sep 30, 2012 at 2:56 PM, רפי וינר rafiw...@gmail.com wrote: Hi i was in an interview and was given a simple function int arrExsits(int* arr,int size,int elem){ for (int i=0;isize;++i) if(elem==arr[i]) return i; return -1; } this function does 2n compares n- the if statment n-check that i is smaller then size i was suppose to give an optimal (less compares) solution so i gave int arrExsits(int* arr,int size,int elem){ if (arr[size-1]==elem) return size-1; arr[size-1]=elem] for (int i=0;;++i) if(elem==arr[i]){ if (i!=size-1) return i; return -1; } this solution works and it has n+2 compares the first one another n and the second inner if. they told me it's good (and I've passed) but they told just for my knowledge that there is a better N compare solution. I've
Re: [algogeeks] GPU doubt
Thanks IIya On Sat, Apr 7, 2012 at 3:53 PM, Ilya Albrekht ilya.albre...@gmail.comwrote: I'm absolutely didn't get your explanation... What is the connection between O(n^3) algorithms and staff you are talking about? On Saturday, 7 April 2012 03:22:29 UTC-7, SAMMM wrote: This is becoz the GPU is multithreaded . In graphics there are three main steps , Application based work where vertex Processing , read the data , pixel processing are done . Secondly come the Culling which which determimes which portion will be shown given the Line of sight . This also checks for any intersection with other objects . For instance a man is present behind the building ,so he should not be visible to us in Graphics or some portion of this body will be shown , This intersection is called redering . The third step if draw . to finally draw the model . These three process are done multithreaded parallerly given 3x Processing speed . You can refer this link below :- http://www.panda3d.org/manual/** index.php/Multithreaded_**Render_Pipelinehttp://www.panda3d.org/manual/index.php/Multithreaded_Render_Pipeline -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/3yqKSMvngHMJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] GPU doubt
@SAMM: what about general mathematical computations such as matrix multiplication which is O(n^3) as such? How do you relate your explanation to such math computations or any algorithm of atleast O(n^3)? On Sat, Apr 7, 2012 at 3:22 AM, SAMM somnath.nit...@gmail.com wrote: This is becoz the GPU is multithreaded . In graphics there are three main steps , Application based work where vertex Processing , read the data , pixel processing are done . Secondly come the Culling which which determimes which portion will be shown given the Line of sight . This also checks for any intersection with other objects . For instance a man is present behind the building ,so he should not be visible to us in Graphics or some portion of this body will be shown , This intersection is called redering . The third step if draw . to finally draw the model . These three process are done multithreaded parallerly given 3x Processing speed . You can refer this link below :- http://www.panda3d.org/manual/index.php/Multithreaded_Render_Pipeline -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] hadoop anyone?
@karthikeyan: Thanks for that info. So in the sample wordcount program using Hadoop pipes in c++ if i want to see data each node has got, I shd query namenode? Is namenode a class or something which contains information or which variable should I check out? Thanks On Sat, Mar 31, 2012 at 2:23 AM, bharat b bagana.bharatku...@gmail.comwrote: but, how can it split the data, if there are dependencies in job ? unless we write parallel program, Does hadoop do any thing faster than usual processor? On Sat, Mar 31, 2012 at 10:32 AM, Karthikeyan V.B kartmu...@gmail.comwrote: Hi, The NameNode splits the job into several tasks and submits to the different DataNode(i.e nodes) , the split size varies from 64KB to 128MB. The NameNode assigns the data split to a datanod. Namenode actually has a table to store the mappings of data node and block stored in it. it is possible to query the namenode and get data from it. Regards, Karthikeyan -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards * * bagana.bharatku...@gmail.com Bharat B | M.Tech II | C.S.E | IITM * * *Ph: +91 8056127652* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] hadoop anyone?
@karthikeyan: Thanks again but I was looking to find that information out from writing code to do so than to use a command on the command line prompt.Any idea? On Sat, Mar 31, 2012 at 10:40 AM, Karthikeyan V.B kartmu...@gmail.comwrote: @bharat : hadoop has a* job tracker* which *resolves the dependencies*and *splits the job into blocks* and *assigns to datanodes* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] hadoop anyone?
Hi all, Has anyone worked on Hadoop before? I ran the wordcount program with Hadoop but I am unable to understand how to find out which node in the cluster got which data? Any experts out here who can suggest? Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: need suggestions
@Don: I am not clear with your explanation. Please can you give me an example? On Wed, Mar 28, 2012 at 6:19 AM, Don dondod...@gmail.com wrote: If you have n processors, start with the n possible ways to select from log2 n items. Assign each processor to find a solution based on the resulting subset of remaining items. Each processor should be able to work fairly independently, and when they are done, they can compare results and find the best one. Don On Mar 27, 10:47 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: Hi all, I am planning to implement a parallel version of the 0-1 knapsack problem. I tried reading up a bit and there are few suggestions here and there. However I would like to know if anyone has an idea or links that I cud refer for this? The main problem in parallelizing a DP algorithm is the dependencies due to recursion? Is there an effective strategy for this?? Using shared memory or message passing approach? Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: need suggestions
Thanks Don! On Wed, Mar 28, 2012 at 7:09 AM, Don dondod...@gmail.com wrote: Let's say that you have 16 processors. You are trying to solve the 0-1 knapsack problem for 40 items. Each item i has size S[i], and you need to find the subset of items which sums as close to T as possible without exceeding T. Pick four of items. There are 16 possible combinations of those items: (none of those 4 items included) 0001 (only item #1 included) ... (all four items included) You will essentially ask each of the 16 processors to solve the knapsack problem for 36 items, starting with one of the 16 possible combiations of the 4 items. Processor 0 will start with none of the first 4 items. Processor 15 will start with all of them, and the other processors will start with a different subset of the items. It may seem like solving the problem for 36 items is not much different than 40, but it requires 1/16th of the work. When each processor is done, it knows the best solution including its assigned items from among the first 4 items. To find the overall best solution you just need to compare the 16 solutions and pick the one best. A possible improvement is to divide up the problem into more parts and farm them out to the processors as they become available. This would work better if you don't have a power of 2 number of processors. It also would reduce the tendancy for some processors to finish early and sit idle while one or two take longer to finish their portion of the work. Don On Mar 28, 9:51 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: @Don: I am not clear with your explanation. Please can you give me an example? On Wed, Mar 28, 2012 at 6:19 AM, Don dondod...@gmail.com wrote: If you have n processors, start with the n possible ways to select from log2 n items. Assign each processor to find a solution based on the resulting subset of remaining items. Each processor should be able to work fairly independently, and when they are done, they can compare results and find the best one. Don On Mar 27, 10:47 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: Hi all, I am planning to implement a parallel version of the 0-1 knapsack problem. I tried reading up a bit and there are few suggestions here and there. However I would like to know if anyone has an idea or links that I cud refer for this? The main problem in parallelizing a DP algorithm is the dependencies due to recursion? Is there an effective strategy for this?? Using shared memory or message passing approach? Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily.- Hide quoted text - - Show quoted text - -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] need suggestions
Hi all, I am planning to implement a parallel version of the 0-1 knapsack problem. I tried reading up a bit and there are few suggestions here and there. However I would like to know if anyone has an idea or links that I cud refer for this? The main problem in parallelizing a DP algorithm is the dependencies due to recursion? Is there an effective strategy for this?? Using shared memory or message passing approach? Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: optimisation
@Gene: if all matrices are of N x N , and my size of L1 cache is L1, then If I need a block of A and B to fit in cache would I need it as 2 x (blocksize )^2 x 8 ( bytes per data item-for example) = L1 ?? or would I need it as 3 ( including C block ) x (blocksize)^2 x 8 = L1 ? Am confused. I tried a sample and I think I got somewhat good speedup for block size 32 ( for matrix dimension 512, 1024 etc )for my L1 of size 16 kbytes and L2 256 kbytes...Any comments or inferences? On Wed, Feb 29, 2012 at 9:31 AM, Arun Vishwanathan aaron.nar...@gmail.comwrote: @all: Thanks a lot On Wed, Feb 29, 2012 at 9:02 AM, Gene gene.ress...@gmail.com wrote: For big matrices, using all the caches well is very important. The usual approach is block tiling as you say. You want two blocks to fit nicely in the L1 cache. The most highly optimized schemes will have a hierarchy of tiles where two tiles at the second level will fit in the L2 cache, etc. Additional levels can be based on memory interfaces, interleaving, page size, and even cylinder size on disk (for really huge matrices). The idea is _never_ to generate more cache misses than you need to. A miss causes a factor of 10 to 1 performance multiple on that operation. Multiplying within the innermost blocks should also consider prefetch: you'll get best performance touching locations in contiguous ascending order. The inner loops are for i = 1 to ma for j = 1 to nb for k = 1 to na r[i,j] += a[i,k] * b[k,j] This ignores that r[i,j] needs to be zeroed out somewhere. But with this assumption, the loops can be juxtaposed in any order without changing the result. You should explore the 6 possible orderings for the best one. Of course you also have to zero out the sums in the best possible manner. FWIW, a GPU will normally outperform a general purpose CPU with ease on this problem. Since even cell phones are getting GPUs these days, tweaking single-processor matrix code is a dying art. Cheers. On Feb 27, 6:57 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: Hi all, We have this challenge to make the fastest executing serial matrix multiplication code. I have tried using matrix transpose( in C for row major ) and loop unrolling.I was able to obtain little speedup. Does anyone have any hints/papers that I could read upon and try to speed up further?I had tried a bit of block tiling but was not successful. Thanks Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: optimisation
@all: Thanks a lot On Wed, Feb 29, 2012 at 9:02 AM, Gene gene.ress...@gmail.com wrote: For big matrices, using all the caches well is very important. The usual approach is block tiling as you say. You want two blocks to fit nicely in the L1 cache. The most highly optimized schemes will have a hierarchy of tiles where two tiles at the second level will fit in the L2 cache, etc. Additional levels can be based on memory interfaces, interleaving, page size, and even cylinder size on disk (for really huge matrices). The idea is _never_ to generate more cache misses than you need to. A miss causes a factor of 10 to 1 performance multiple on that operation. Multiplying within the innermost blocks should also consider prefetch: you'll get best performance touching locations in contiguous ascending order. The inner loops are for i = 1 to ma for j = 1 to nb for k = 1 to na r[i,j] += a[i,k] * b[k,j] This ignores that r[i,j] needs to be zeroed out somewhere. But with this assumption, the loops can be juxtaposed in any order without changing the result. You should explore the 6 possible orderings for the best one. Of course you also have to zero out the sums in the best possible manner. FWIW, a GPU will normally outperform a general purpose CPU with ease on this problem. Since even cell phones are getting GPUs these days, tweaking single-processor matrix code is a dying art. Cheers. On Feb 27, 6:57 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: Hi all, We have this challenge to make the fastest executing serial matrix multiplication code. I have tried using matrix transpose( in C for row major ) and loop unrolling.I was able to obtain little speedup. Does anyone have any hints/papers that I could read upon and try to speed up further?I had tried a bit of block tiling but was not successful. Thanks Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] optimisation
Hi all, We have this challenge to make the fastest executing serial matrix multiplication code. I have tried using matrix transpose( in C for row major ) and loop unrolling.I was able to obtain little speedup. Does anyone have any hints/papers that I could read upon and try to speed up further?I had tried a bit of block tiling but was not successful. Thanks Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] suggestions?
hi, I need to a final project in a course called Parallel Programming. Does anyone have suggestions for a good topic to take up in this??Some challenging problem maybe that is computationally intensive but can benefit from multicore and parallel processing. Thanks! -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: suggestions?
Thanks Gene! On Sun, Feb 12, 2012 at 3:17 PM, Gene gene.ress...@gmail.com wrote: If you want to do something of practical importance that has not already been done many times, you can look at parallel collision detection. Collision detection is very important in physical simulations (as in mechanical design tools, CGI, and computer games). On Feb 12, 10:58 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: hi, I need to a final project in a course called Parallel Programming. Does anyone have suggestions for a good topic to take up in this??Some challenging problem maybe that is computationally intensive but can benefit from multicore and parallel processing. Thanks! -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] openmp
hi , i am trying to run this small code with open mp but I dont see any threads created . The code compiles with -fopenmp but does not create threads to run parallel.For example, main() { omp_set_num_threads(4); #pragma omp parallel printf( hello world from %d\n ,omp_get_thread_num()); return; } output: hello world from 0 what abt the other threads?? -- -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] openmp
I use g++ On Sun, Feb 5, 2012 at 12:39 PM, Rahul raikra...@gmail.com wrote: which compiler or which environment I use Microsoft Visual Studio with Microsoft HPC Pack A syntax error is visible use { On 2/6/12, Arun Vishwanathan aaron.nar...@gmail.com wrote: hi , i am trying to run this small code with open mp but I dont see any threads created . The code compiles with -fopenmp but does not create threads to run parallel.For example, main() { omp_set_num_threads(4); #pragma omp parallel printf( hello world from %d\n ,omp_get_thread_num()); return; } output: hello world from 0 what abt the other threads?? -- -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] openmp
hey , I just figured out the problem. the -fopenmp was to be included in a couple of places in my makefile due to which the openmp library was not getting recognised though code was compiling. Anyways if it is just one line of code and u dont need the braces after omp parallel( it is just like a one line statement after 'if') i have dual core. thanks for yr help! On Sun, Feb 5, 2012 at 12:49 PM, Rahul raikra...@gmail.com wrote: See a hello world tutorial as far as I can see is that you haven't put {} in the section of code you want to run parallel how many processors do you have try running without asking number of threads .you must see as many outputs as number of processors On 2/6/12, Arun Vishwanathan aaron.nar...@gmail.com wrote: I use g++ On Sun, Feb 5, 2012 at 12:39 PM, Rahul raikra...@gmail.com wrote: which compiler or which environment I use Microsoft Visual Studio with Microsoft HPC Pack A syntax error is visible use { On 2/6/12, Arun Vishwanathan aaron.nar...@gmail.com wrote: hi , i am trying to run this small code with open mp but I dont see any threads created . The code compiles with -fopenmp but does not create threads to run parallel.For example, main() { omp_set_num_threads(4); #pragma omp parallel printf( hello world from %d\n ,omp_get_thread_num()); return; } output: hello world from 0 what abt the other threads?? -- -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] java help
Hi, does anybody know how to take a screenshot of screen with java ? I also need help regarding storing the screenshot image into a doc file or so. Any suggestions? -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Mathematical formula
I wanted to gather some analysis on parallelism for matrix multiplication. Amdahl 's law essentially compares speed when work is done serially to speed when some parallelism is introduced in the system. Say I have Tcount threads used for computation on a system having NCores number of cores. Say dimension of all matrices is NxN. If code was completely sequential then N^3 I guess would be amount of work done. How would be the case when Tcount threads are used? say I have each thread performing calculation for certain number of rows. So if I have matrix dimension N and Tcount threads then each thread calculates N/Tcountnumber of rows , and for each row it takes N^ 2 work units serially. How much time would it now take with threads? I thought it would be n^3 work serially but if parallelism is involved it would be (n/tcount)*n^2 * tcount/ncores... But this causes tcount to cancel out which looks absurd. Any suggestions? -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] MS Question -Reverse a Linked List in size of 2
node *ptr =head; //function call is reverse(head,NULL) void reverse(node *ptr, node *follow) { if(ptr-next!=NULL ptr-next-next!=NULL) reverse(ptr-next-next,ptr); else if(ptr-next!=NULL ptr-next-next==NULL) { ptr-next-next=follow; head=ptr; } ptr-next-next=follow; if(follow!=NULL) follow-next-next=NULL; } @ankur: if odd number of nodes then maybe just ask interviewer how he wants it to be and try including that case ;) } On Mon, Jan 23, 2012 at 10:32 AM, Ankur Garg ankurga...@gmail.com wrote: wat if u have odd no of nodes On Tue, Jan 24, 2012 at 12:00 AM, atul anand atul.87fri...@gmail.comwrote: one simple way would be using stacks. push node,node-next; then pop() , and reversing the pointers. On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg ankurga...@gmail.comwrote: Say LL is 1-2-3-4-5-6-7-8 Then u need to return 7-8-5-6-3-4-1-2 U cant swap the values U have to rearrange the ptr... -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sort 2D array
@lucifer:nice explanation !... just to make a small clarification, in your stabilisation part u jus compare x with min (b,d) , make a swap if necessary and then next time u compare it shud be =min(b,d) and so u break. x b c d e f g h i so now after breaking x is less than both b and d but present b could be greater than e right? for example initally it cud be 8 5 6 7. . . . and we swap 8 and 5now 8 is above 7 after swap ...but is this taken care of next iteration when we do swaps of a[row][col] with a[row+1][0]?? so is heapify sep in all just comparison of x with b and d only and swap if needed?? On Sat, Jan 14, 2012 at 1:48 AM, Gaurav Kalra gvka...@gmail.com wrote: Bases on algorithm suggested by Lucifer, I have coded the problem in C (please see attachment). The code has been tested against the following test cases: 1 3 4 8 9 2 5 18 25 50 6 7 22 45 55 and 1 2 7 3 5 8 4 6 9 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/kQ0gKL_2h7oJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Generate all possible binary trees given in-order traversal
@lucifer: in yr code will not all the root-left be NULL for each iteration as startindex is always greater than endindex ( i.e i-1) in the recursive function call??and so for each node only root-right is made? On Fri, Dec 30, 2011 at 12:51 AM, praveen raj praveen0...@gmail.com wrote: yes... right... i forget to remove this statement.. PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING On Fri, Dec 30, 2011 at 2:17 PM, Lucifer sourabhd2...@gmail.com wrote: @praveen I think what u are doing above is the following: Say, F(n) denotes the no. of binary trees that can be formed using N elements given the inorder sequence.. F(n) = SumOver(i= 1 to N) { F(i-1) * F(N-i) } which is nothing but.. F(N) = (2n C n)/ (n+1) i.e. catalan's no. Also, i would like to mention that in ur code probably u need to remove the following condition otherwise u result outcome will always be zero.. * if(N==0) return 0; On 30 Dec, 13:41, praveen raj praveen0...@gmail.com wrote: int countBT(int N) { int count =0; int count1; if(N==0) return 0; if(N=1) return 1; else { for(int j=1;j=N;j++) { count1 = countBT(j-1) count2 =countBT(N-j); count+=(count1*count2); } return (count); } } PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sort 2D array
@lucifer: yes I get that...I was just saying that after a swap has happened within the while loop ( since x min(b,d) might have been the case ) , then in the next looping within while, break wud happen right? meaning it doesnt stay in the while after a swap happens... On Sun, Jan 22, 2012 at 3:25 PM, Lucifer sourabhd2...@gmail.com wrote: @Arun If you read the post in which i have explained the process properly, the following is also present: while(1) { If x = min (b,d ), /* here b is nothing but the element placed next to 'x' on the same row.. d is the element placed right below 'x' in the same column... then we are done...*/ break; else swap ('x', min (b,d)) } If you see in the comments i have mentioned that b and d are not exactly the same b and d as shown in the matrix.. but they are current right and current bottom elements of 'x'.. Hence, the swaps go on till the condition x = min (b,d ) is not satisfied.. On Jan 23, 3:44 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: @lucifer:nice explanation !... just to make a small clarification, in your stabilisation part u jus compare x with min (b,d) , make a swap if necessary and then next time u compare it shud be =min(b,d) and so u break. x b c d e f g h i so now after breaking x is less than both b and d but present b could be greater than e right? for example initally it cud be 8 5 6 7. . . . and we swap 8 and 5now 8 is above 7 after swap ...but is this taken care of next iteration when we do swaps of a[row][col] with a[row+1][0]?? so is heapify sep in all just comparison of x with b and d only and swap if needed?? On Sat, Jan 14, 2012 at 1:48 AM, Gaurav Kalra gvka...@gmail.com wrote: Bases on algorithm suggested by Lucifer, I have coded the problem in C (please see attachment). The code has been tested against the following test cases: 1 3 4 8 9 2 5 18 25 50 6 7 22 45 55 and 1 2 7 3 5 8 4 6 9 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/kQ0gKL_2h7oJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Generate all possible binary trees given in-order traversal
@lucifer: sorry if i seem to be missing the ppoint...can u just clarify what I am getting wrong here.. if array is a[0] a[1] a[2] a[3] a[4] say, i understand yr recursion goes as follows: the first node data is a[0], its left pointer is null ( since call is made with startindex=1 and lastindex =0 and so null is returned ) and its right pointer points to node whose data is a[1], whose left pointer is null (since call made with startindeex =2 and lastindex =1 )and whose right pointer points to node whose data is a[2] whose left pointer is null and right points to node whose data is a[3] and so on.. am sorry if it sounds silly...can u clarify if am seeing it wrong?? On Sun, Jan 22, 2012 at 3:31 PM, Lucifer sourabhd2...@gmail.com wrote: @Arun.. Are you referring to the following condition in 'GenerateBT': /* if ( startIndex endIndex) return NULL; */ If so, then answer is no. The above condition basically identifies that we have reached a leaf node and hence, the leaf node should have both its left and right pointers set to NULL. If you trace it. you will figure it out. In case there is a doubt do let me know.. On Jan 23, 4:17 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: @lucifer: in yr code will not all the root-left be NULL for each iteration as startindex is always greater than endindex ( i.e i-1) in the recursive function call??and so for each node only root-right is made? On Fri, Dec 30, 2011 at 12:51 AM, praveen raj praveen0...@gmail.com wrote: yes... right... i forget to remove this statement.. PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING On Fri, Dec 30, 2011 at 2:17 PM, Lucifer sourabhd2...@gmail.com wrote: @praveen I think what u are doing above is the following: Say, F(n) denotes the no. of binary trees that can be formed using N elements given the inorder sequence.. F(n) = SumOver(i= 1 to N) { F(i-1) * F(N-i) } which is nothing but.. F(N) = (2n C n)/ (n+1) i.e. catalan's no. Also, i would like to mention that in ur code probably u need to remove the following condition otherwise u result outcome will always be zero.. * if(N==0) return 0; On 30 Dec, 13:41, praveen raj praveen0...@gmail.com wrote: int countBT(int N) { int count =0; int count1; if(N==0) return 0; if(N=1) return 1; else { for(int j=1;j=N;j++) { count1 = countBT(j-1) count2 =countBT(N-j); count+=(count1*count2); } return (count); } } PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sort 2D array
@ lucifer: thank you ! On Sun, Jan 22, 2012 at 4:12 PM, Lucifer sourabhd2...@gmail.com wrote: @Arun, Nope.. the loop exits only when there are no more swaps possible... Let me explain with an example.. x b c d e f g h i say x min(b,d) , where min(b,d) = b, Hence, swap happens.. b x c d e f g h i say, x min(c, e), where min(c,e) = e.. Hence, swap takes place.. b e c d x f g h i Now say, x = min(f,h).. Hence, we hit the break statement and exit from the loop.. On Jan 23, 5:03 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: @lucifer: yes I get that...I was just saying that after a swap has happened within the while loop ( since x min(b,d) might have been the case ) , then in the next looping within while, break wud happen right? meaning it doesnt stay in the while after a swap happens... On Sun, Jan 22, 2012 at 3:25 PM, Lucifer sourabhd2...@gmail.com wrote: @Arun If you read the post in which i have explained the process properly, the following is also present: while(1) { If x = min (b,d ), /* here b is nothing but the element placed next to 'x' on the same row.. d is the element placed right below 'x' in the same column... then we are done...*/ break; else swap ('x', min (b,d)) } If you see in the comments i have mentioned that b and d are not exactly the same b and d as shown in the matrix.. but they are current right and current bottom elements of 'x'.. Hence, the swaps go on till the condition x = min (b,d ) is not satisfied.. On Jan 23, 3:44 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: @lucifer:nice explanation !... just to make a small clarification, in your stabilisation part u jus compare x with min (b,d) , make a swap if necessary and then next time u compare it shud be =min(b,d) and so u break. x b c d e f g h i so now after breaking x is less than both b and d but present b could be greater than e right? for example initally it cud be 8 5 6 7. . . . and we swap 8 and 5now 8 is above 7 after swap ...but is this taken care of next iteration when we do swaps of a[row][col] with a[row+1][0]?? so is heapify sep in all just comparison of x with b and d only and swap if needed?? On Sat, Jan 14, 2012 at 1:48 AM, Gaurav Kalra gvka...@gmail.com wrote: Bases on algorithm suggested by Lucifer, I have coded the problem in C (please see attachment). The code has been tested against the following test cases: 1 3 4 8 9 2 5 18 25 50 6 7 22 45 55 and 1 2 7 3 5 8 4 6 9 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/kQ0gKL_2h7oJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Generate all possible binary trees given in-order traversal
@lucifer: my bad ...thanks a lot On Sun, Jan 22, 2012 at 4:27 PM, Lucifer sourabhd2...@gmail.com wrote: @Arun.. I think you are generating the bin-tree for ' i =startIndex' and not ' i =startIndex +1'.. Hence, if you just trace it for ' i =startIndex + 1' for all the recursive calls, you should get it... On Jan 23, 5:22 am, Lucifer sourabhd2...@gmail.com wrote: @Arun... You are not getting it wrong but then you have just generated one binary tree.. What about the other bin-trees...? The bin-tree that you are generating is for the first recursive iteration.. Let me give you a quick explanation... GenerateBT has the following loop.. for (int i =startIndex ; i =endIndex; ++i) {} Now, the bin-tree that you are generating is for i = startIndex + 1, and also when you recursively go inside you are basically tracing it for 'i = startIndex + 1'.. Try doing it for i = startIndex + 3 (say).. and also ensure that when you go inside recursively try to trace the case where 'i startIndex + 1' and see if you get it.. On Jan 23, 5:11 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: @lucifer: sorry if i seem to be missing the ppoint...can u just clarify what I am getting wrong here.. if array is a[0] a[1] a[2] a[3] a[4] say, i understand yr recursion goes as follows: the first node data is a[0], its left pointer is null ( since call is made with startindex=1 and lastindex =0 and so null is returned ) and its right pointer points to node whose data is a[1], whose left pointer is null (since call made with startindeex =2 and lastindex =1 )and whose right pointer points to node whose data is a[2] whose left pointer is null and right points to node whose data is a[3] and so on.. am sorry if it sounds silly...can u clarify if am seeing it wrong?? On Sun, Jan 22, 2012 at 3:31 PM, Lucifer sourabhd2...@gmail.com wrote: @Arun.. Are you referring to the following condition in 'GenerateBT': /* if ( startIndex endIndex) return NULL; */ If so, then answer is no. The above condition basically identifies that we have reached a leaf node and hence, the leaf node should have both its left and right pointers set to NULL. If you trace it. you will figure it out. In case there is a doubt do let me know.. On Jan 23, 4:17 am, Arun Vishwanathan aaron.nar...@gmail.com wrote: @lucifer: in yr code will not all the root-left be NULL for each iteration as startindex is always greater than endindex ( i.e i-1) in the recursive function call??and so for each node only root-right is made? On Fri, Dec 30, 2011 at 12:51 AM, praveen raj praveen0...@gmail.com wrote: yes... right... i forget to remove this statement.. PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING On Fri, Dec 30, 2011 at 2:17 PM, Lucifer sourabhd2...@gmail.com wrote: @praveen I think what u are doing above is the following: Say, F(n) denotes the no. of binary trees that can be formed using N elements given the inorder sequence.. F(n) = SumOver(i= 1 to N) { F(i-1) * F(N-i) } which is nothing but.. F(N) = (2n C n)/ (n+1) i.e. catalan's no. Also, i would like to mention that in ur code probably u need to remove the following condition otherwise u result outcome will always be zero.. * if(N==0) return 0; On 30 Dec, 13:41, praveen raj praveen0...@gmail.com wrote: int countBT(int N) { int count =0; int count1; if(N==0) return 0; if(N=1) return 1; else { for(int j=1;j=N;j++) { count1 = countBT(j-1) count2 =countBT(N-j); count+=(count1*count2); } return (count); } } PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily
Re: [algogeeks] Re: Divisibility by five
@dave or anyone: can u pls explain the logic of n3 in dave's solution? why is it subtracted from n(which is divided by 4 using 2) and what does n 3 indicate? On Sat, May 7, 2011 at 9:38 AM, Dave dave_and_da...@juno.com wrote: @Umer: Do you suppose that you can convert an int into a string without using division or mod, either directly or indirectly? Dave On May 4, 1:12 am, Umer Farooq the.um...@gmail.com wrote: I'm surprised to see that why are you guys making this problem so complex. This problem can be solved in two steps only. 1- Convert the given int into string 2- Check if the last character is 0 or 5. // it yes, then return true else return false for e.g. 125 (last character is 5 ... therefore it is divisible by 5) 120 (last character is 0 ... therefore it is divisible by 5) 111 (last character is 1 ... therefore it is not divisible by 5) The pseudo-code has been written in my above email. On Wed, May 4, 2011 at 1:49 AM, Dave dave_and_da...@juno.com wrote: @anshu: Spoiler alert... I was thinking of something more along the line int DivisibleBy5 (int n) { n = n 0 ? n : -n; while( n 0 ) n = (n 2) - (n 3); return (n == 0); } To see that it works, write n as n = 4*a + b, where 0 = b = 3. Then the iteration replaces n by a - b. Consider (4*a + b) + (a - b), the sum of two consecutive values of n. This simplifies to 5*a, which is a multiple of 5. Thus, n is a multiple of 5 before an iteration if and only if it also is a multiple of 5 afterwards, It is clearly log n because n is replaced by a number no greater than n/4 on each iteration. Examples: n = 125. The sequence of iterates is 30, 5, 0. Ergo, 125 is a multiple of 5. n = 84. The sequence of iterates is 21, 4, -1. Ergo, 84 is not a multiple of 5. Dave On May 3, 3:13 am, anshu anshumishra6...@gmail.com wrote: algorithm: if any number(a) is divisible by 5 it can be wriiten as 4*b + b -- this cleary shows the last two bit of a b will be same. lets understand by an example (35)10 = (100011)2 xx1100 + xx11 - 100011 now this clearly shows we can calculate the unknowns(x) by traversing right to left code: int main() { int n, m; cin n; m = n; int a, b; int i=2; a = (m3)2; b = (m3); m = 2; bool rem = 0,s,r; while (m3) { r = a(1i); s = r^(m1)^rem; b = b|(si); a = a|(s(i+2)); rem = (rs)|(srem)|(rrem) ; i++; m = 1; } if (a+b == n) cout yes\n; else cout no\n; return 0; }- Hide quoted text - - Show quoted text - -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Umer- Hide quoted text - - Show quoted text - -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] how to convert a floating point number into binary representation.
@immanuel: in this part while (decimalPart 0 decimalPart 1 str.length 64) { decimalPart *= 2; str[str.length] = (decimalPart - 0) + '0'; } is this decimalPart-0 correct here? if decimalpart (say) starts as 0.584 then after doing that into 2 we 1.164. What happens next according to your code? On Tue, May 24, 2011 at 1:45 AM, immanuel kingston kingston.imman...@gmail.com wrote: correct me if I am wrong. String convertFloatToBinary(float num) { String str = ; int numBeforeDecimal = (int)num; float decimalPart = num - (float)numBeforeDecimal; int sign=1; if (numBeforeDecimal 0 ) sign = -1; if (sign 0) str[str.length] = '-'; while(numBeforeDecimal 0) { str[str.length] = numBeforeDecimal % 2 + '0'; numBeforeDecimal /= 2; } str[str.length] = '.'; while (decimalPart 0 decimalPart 1 str.length 64) { decimalPart *= 2; str[str.length] = (decimalPart - 0) + '0'; } return str; } Thanks, Immanuel On Tue, May 24, 2011 at 12:15 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: http://kipirvine.com/asm/workbook/floating_tut.htm On Tue, May 24, 2011 at 12:09 PM, saurabh agrawal saurabh...@gmail.comwrote: -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers Naveen Kumar -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: distinct substring
@juver: further explanation? On Tue, Jan 25, 2011 at 6:27 AM, juver++ avpostni...@gmail.com wrote: suffix trees. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: google questions
@all: how is the problem solved using a heap...can someone explain. did not understand what was on the net... On Thu, Feb 3, 2011 at 2:23 AM, Avik Mitra tutai...@gmail.com wrote: I am proposing a solution for problem 2.. 2. Given a text file, implement a solution to find out if a pattern similar to wild cards can be detected. fort example find if a*b*cd*, or *win or *def* exists in the text. Whatever be the pattern sort it must be regular expression. So in principle, there always exists a deterministic finite automata with exactly one finite state to accept the pattern. Thus, the problem can be solved. For example take the case for a*b*cd*. The automaton can can written as: 1.Set state=1. 2. Scan the string until end of string is reached. 2.1. If state is 1 and the letter is a then do not change the state. If the state is 1 and the letter is b then go to state 2. if the state is 1 and the letter is c then go to state 3. if the state is 1 and the letter is d then go to state 4. if the state is 2 and letter is a then go to state 4. if the state is 2 and the letter is b then do not change the state. if the state is 2 and the letter is c the go to state 3. if the state is 2 and the letter is d then go to state 4. if the state is 3 and the letter is a,b or c then go to state 4. if the state is 3 and the letter is d then do not change state. if the state is 4 then do not change state. 3. If the state is 3 output accept else output reject. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Divisibility by five
@dave: thanks for that..but i just wanted to know as to how u thot of converting n to a-b in the iteration. when u say 4a +b is a multiple of 5 iff a-b is a muliple of 5 i was able to get that only when i tried an example...if they ask divisbility by 3 or 6 or 7 how wud the logic change?? On Sat, Jan 21, 2012 at 9:34 AM, karthikeyan muthu keyankarthi1...@gmail.com wrote: check the last char ... it should be 0 or 5 , int to string without mod On Sat, Jan 21, 2012 at 10:05 PM, Dave dave_and_da...@juno.com wrote: @Karthikeyan: Is this supposed to relate to the question of determining divisibility by 5? Dave On Jan 21, 9:25 am, karthikeyan muthu keyankarthi1...@gmail.com wrote: @dave int no=10; char ans[100]; sprintf(ans,%d,no); coutans; On Fri, Jan 20, 2012 at 10:29 PM, Arun Vishwanathan aaron.nar...@gmail.comwrote: @dave or anyone: can u pls explain the logic of n3 in dave's solution? why is it subtracted from n(which is divided by 4 using 2) and what does n 3 indicate? On Sat, May 7, 2011 at 9:38 AM, Dave dave_and_da...@juno.com wrote: @Umer: Do you suppose that you can convert an int into a string without using division or mod, either directly or indirectly? Dave On May 4, 1:12 am, Umer Farooq the.um...@gmail.com wrote: I'm surprised to see that why are you guys making this problem so complex. This problem can be solved in two steps only. 1- Convert the given int into string 2- Check if the last character is 0 or 5. // it yes, then return true else return false for e.g. 125 (last character is 5 ... therefore it is divisible by 5) 120 (last character is 0 ... therefore it is divisible by 5) 111 (last character is 1 ... therefore it is not divisible by 5) The pseudo-code has been written in my above email. On Wed, May 4, 2011 at 1:49 AM, Dave dave_and_da...@juno.com wrote: @anshu: Spoiler alert... I was thinking of something more along the line int DivisibleBy5 (int n) { n = n 0 ? n : -n; while( n 0 ) n = (n 2) - (n 3); return (n == 0); } To see that it works, write n as n = 4*a + b, where 0 = b = 3. Then the iteration replaces n by a - b. Consider (4*a + b) + (a - b), the sum of two consecutive values of n. This simplifies to 5*a, which is a multiple of 5. Thus, n is a multiple of 5 before an iteration if and only if it also is a multiple of 5 afterwards, It is clearly log n because n is replaced by a number no greater than n/4 on each iteration. Examples: n = 125. The sequence of iterates is 30, 5, 0. Ergo, 125 is a multiple of 5. n = 84. The sequence of iterates is 21, 4, -1. Ergo, 84 is not a multiple of 5. Dave On May 3, 3:13 am, anshu anshumishra6...@gmail.com wrote: algorithm: if any number(a) is divisible by 5 it can be wriiten as 4*b + b -- this cleary shows the last two bit of a b will be same. lets understand by an example (35)10 = (100011)2 xx1100 + xx11 - 100011 now this clearly shows we can calculate the unknowns(x) by traversing right to left code: int main() { int n, m; cin n; m = n; int a, b; int i=2; a = (m3)2; b = (m3); m = 2; bool rem = 0,s,r; while (m3) { r = a(1i); s = r^(m1)^rem; b = b|(si); a = a|(s(i+2)); rem = (rs)|(srem)|(rrem) ; i++; m = 1; } if (a+b == n) cout yes\n; else cout no\n; return 0; }- Hide quoted text - - Show quoted text - -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Umer- Hide quoted text - - Show quoted text - -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- You received this message because you
Re: [algogeeks] Re: vertical level sum in Binary tree
my god why do companies question like this??? On Sat, Jan 21, 2012 at 4:10 AM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: yes atul I wanted to say only that may be not able to convey it . n is maximum number of vertical lines sum that you can calculate On 1/21/12, atul anand atul.87fri...@gmail.com wrote: @ UTKARSH : how will you calculate number of vertical lines before passing it to vsum(). i guess n should be max(no. of nodes to the extreme left from the root , no. of nodes to the extreme right from root) On Fri, Jan 20, 2012 at 10:35 PM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: void vsum(struct node *p ,int i) { if(p) { sum[i] = sum[i] + p-data; vsum(p-left,i-1); vsum(p-right,i+1); } } construct an array of int sum[n] where n will be maximum no. of vertical lines and call vsum with vsum(root,n/2) On Fri, Jan 20, 2012 at 9:06 PM, sravanreddy001 sravanreddy...@gmail.comwrote: what does it mean.. we cannot use an array? (a static array?) a vector is an array..but a dynamic one... what other DS can be used? a linked list allowed? (each of the two algorithms can be mate to work with linked list too... (except that it takes more time.. ) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/GN5SzfqtYlgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: vertical level sum in Binary tree
no jst thinking if any practical application of this sort of thing..:) On Sat, Jan 21, 2012 at 3:11 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: why arun? On Sun, Jan 22, 2012 at 1:44 AM, Arun Vishwanathan aaron.nar...@gmail.com wrote: my god why do companies question like this??? On Sat, Jan 21, 2012 at 4:10 AM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: yes atul I wanted to say only that may be not able to convey it . n is maximum number of vertical lines sum that you can calculate On 1/21/12, atul anand atul.87fri...@gmail.com wrote: @ UTKARSH : how will you calculate number of vertical lines before passing it to vsum(). i guess n should be max(no. of nodes to the extreme left from the root , no. of nodes to the extreme right from root) On Fri, Jan 20, 2012 at 10:35 PM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: void vsum(struct node *p ,int i) { if(p) { sum[i] = sum[i] + p-data; vsum(p-left,i-1); vsum(p-right,i+1); } } construct an array of int sum[n] where n will be maximum no. of vertical lines and call vsum with vsum(root,n/2) On Fri, Jan 20, 2012 at 9:06 PM, sravanreddy001 sravanreddy...@gmail.comwrote: what does it mean.. we cannot use an array? (a static array?) a vector is an array..but a dynamic one... what other DS can be used? a linked list allowed? (each of the two algorithms can be mate to work with linked list too... (except that it takes more time.. ) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/GN5SzfqtYlgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] anybody having K and R ebook?
hey sorry if it seems offtopic to post here...but does anybody have an ecopy of this book?I tried searching but cudnt find one properly. thanks in advance! -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon - Longest palindrome in a string in O(n)
@varun : isn't the longest common subsequence abccba and longest common substring is abc or cba?in any case what is the longest palindrom in the given string abcdecba?? isnt it the individual letters itself ie length max is 1? On Wed, Jun 22, 2011 at 10:45 AM, varun gupta varun.gt...@gmail.com wrote: 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: 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 unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Warm Regards, Varun Kumar Email Id: varun.gt...@gmail.com Contact: +91-9711751235 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Sorting for large data
@ all : can someone provide me a good link to reading on external sort? and k way merging? is this also a useful way to sort when the number of records is large compared to memory size but many entries in the records are repeated elements? On Tue, Jan 17, 2012 at 6:42 AM, sravanreddy001 sravanreddy...@gmail.comwrote: I agree with Gene, 10^80 is of very larger magnitude, and is no way possible to solve given any amount of time, He might be testing you to '*think it practically before jumping to answer the question*' (or) he/you must have gone wrong somewhere. (even to read that input it takes for ever..) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/bgGIa4EQ1Q4J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] MS question
Given large number of elements. All elements belong to range 1 to 27000. First case no elements repeated and second case elements are repeated. memory capacity is 4k. How to sort efficiently? -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: adobe written round que
@all : doesnt sudhir's solution seem to work?? @sudhir: can u explain yr logic? On Wed, Sep 21, 2011 at 8:31 AM, annarao kataru kataruanna...@gmail.comwrote: can u explain the logic behind this thanks in advance -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Doubt in C++
@lucifer: ok so you are saying that the constructor implicitly creates a temporary 'string' object to hold this char string which is then assigned to s2. Does this mean that if a constructor function was not specified (unlike here where we have a parameterized constructor) this would not work or does this sort of assingment require a single paramterized constructor? On Tue, Jan 3, 2012 at 12:31 AM, Lucifer sourabhd2...@gmail.com wrote: @above.. This is what i assume is happening ( apart from inherent compiler optimization is any)...Let me know if i m wrong.. when s2=name; is done it should call the overloaded equal to operator.. But, 'name' is not a string object, its basically a char pointer to a const string test.. Now, for simplicity lets assume that name is char array.. Now, given a binary operator, for the operation to take place both the operands ideally should be of the same type... For ex: int a; a = 10.0; Here, 10.0 is double and a is int, for the assignment to work first 10.0 will be converted to int data type and then assigned to a.. In case, the right hand side of a = operator cannot be converted to the left hand side type, then ideally an incompatible assignment shall be thrown.. Going back to the above example... conversion of 10.0 to 10 is basically performed as part of implicit conversion or type propagation as part of basic data types (supported by the compiler)... Now class is a custom data type and hence, we don't expect the compiler to randomly convert from any data type to the class type for the '=' operator to work.. Then how is it done.. Basically constructors of a class act as implicit type converters as well... Hence, for statement similar to s2 = name; If 'name' is not of the type of s2 i.e.'string' type then it will try to look for implicit conversions.. Now, a constructor of a class acts as an implicit converter as well.. and a 'string' class has a constructor 'string(char *)', it will use 'string(char*)' constructor to construct a temporary intermediate string object which will hold the value 'test' and then assign to s2... Once, assignment operation is over, the temporary string object containing the value 'test' will be destroyed.. On Jan 3, 12:05 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: I just have a basic doubt..does the string s1,s2 statement call any default constructor?or is it that it is not performed since parameterised constructor is present? On Wed, Sep 21, 2011 at 1:31 AM, vijay singh vijaysinghb...@gmail.com wrote: It is because of the presence of the single parameterised constructor in the class definition. So, if we are writing the following statement... string s1; s1=test; It'll call the single parameterised constructor. But this only true in the case of single value assignment as in the above statement.. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sqrt function...
@gene: I checked the wiki link given..In that it is mentioned that initial root is chosen as 2.10^n or 6.10^n based on the number of digits being even or odd in the number. The concept of choosing 2 or 6 in this formula is based on some geometric mean concept mentioned. Can you please clarify what they mean to say? I wasnt able to follow that... On Sun, Sep 25, 2011 at 3:06 AM, Gene gene.ress...@gmail.com wrote: Binary search isn't the right term. Rather you want bisection. But for each iteration it adds only one bit to the precision of the answer. You should also look at Newton's method. It doubles the number of bits of precision in each iteration. Algorithm: float sqrt(float x) root = intial guess while root^2 is not close enough to x do root = (x / root + root) / 2; return root; Wikipedia has a nice article with more details and in particular how to get a good initial guess. http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Taylor_series On Sep 25, 8:29 am, Vikram Singh singhvikram...@gmail.com wrote: ok.. thanks guys... one doubt now... if this ques is asked in an interview(its already been asked in ms interview)... then u cant just write the code... u hv to explain the whole approach like why u r choosing that way to narrowing dowm the range... so pls explain how this sol is derived... On Sun, Sep 25, 2011 at 10:15 AM, keyan karthi keyankarthi1...@gmail.comwrote: binary search!!! :) On Sat, Sep 24, 2011 at 11:38 PM, sunny agrawal sunny816.i...@gmail.comwrote: let x be the number initialize ans to some value like x or x/2 now repeatedly do the following ans = (ans + x/ans)/2 each time you perform this operation you will move closer to the sqrt value and depending upon the precision required stop On Sat, Sep 24, 2011 at 11:17 PM, siddharth srivastava akssps...@gmail.com wrote: On 24 September 2011 13:45, shady sinv...@gmail.com wrote: one of the simplest way is to do binary search... :) +1 On Sat, Sep 24, 2011 at 8:42 PM, teja bala pawanjalsa.t...@gmail.comwrote: http://www.geeksforgeeks.org/archives/3187 check dis one. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Siddharth Srivastava -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Sunny Aggrawal B.Tech. V 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 unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - - Show quoted text - -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at
Re: [algogeeks] Re: Doubt in C++
@lucifer: thanks ! On Tue, Jan 3, 2012 at 9:02 AM, Lucifer sourabhd2...@gmail.com wrote: @Arun... Basically what u have asked boils down to 2 questions... 1. First, this sort of assignment requires single parameterized constructor ? Yes ( and No as well in special cases.). But its not a mandate that the class defines... There is something called as implicit and explicit construction... Class X { public: X(){} // default constructor... X(int a) // single param constr X( int a, double b) // const with 2 parameters... }; Now there are 2 ways of creating an object of class X which takes only one parameter.. a) X obj(10); // this is the most common way of doing it... // also here we are explicitly asking the compiler to use a particular constr whose prototype should match X(int ); b) X obj = 10; // this is more uncommon way of doing it.. // here , an implicit conversion happens and it goes as follows: /* i) X temp = X(10); // creating temp object.. ii) X obj = temp; // overloaded '=' operator called iii) temp.~temp(); // destruct temp... Though, theoritically this is how it should create obj.. But, due to compiler optimization a temporary object is not created and destroyed... But, to verify that there is a difference b/w implicit and explicit creation, u can look at generated assembly code and see that a reduntant copy operation is present in the assembly level code.. This redundant copy code is to mimic the usage of default '=' overloaded operator...i.e something similar to * mov bx, bx * */ Given the above explanation we can say that we want to implicitly create an object which takes 2 parameters... Now, given the fact that '=' is a binary operator, there is no way we can use more than 2 parameters in the expression.. Say, i want to create: X obj(10, 2.0), implicitly... then ' X obj = 10 20 ' needs to be a valid expression.. Basically for this is happen there needs to be a way where the rhs can take more than 2 expression values.. which is not possible... Hence, implicit creation of objects only work with single parameterized constructors... Now, you must have seen that i have used the following statement above: *But its not a mandate that the class defines...* - the above explanation should justify this statement.. *Yes ( and No as well in special cases.* - *Yes* is obvious as per the above explanation... Now, to show what *No* meant, say class X has the following constructor instead of the single parameterized constructor... /// X( int a, char *b = NULL, bool b = true); /// Now, by looking at it we can say that its not a single parameterized constr..hence it can't be used in implicit construction.. But thats not true as the constructor as got default parameters except the first one which is int type... Hence, given the above constructor.. X obj = 10, is still valid... 2. Does this mean that if a constructor function was not specified (unlike here where we have a parameterized constructor) this would not work ? Yes, should be self explanatory.. Though its obvious but a conversion only works when RHS of '=' operator can itself be assigned to the formal argument parameter of a constructor... Basically what i mean from the above statement is, apart from the basic types... it can also work for related(different not same) class types... say, the formal parameter of constrcutor has a base class type and the RHS of '=' has a derieved class type... On Jan 3, 7:52 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: @lucifer: ok so you are saying that the constructor implicitly creates a temporary 'string' object to hold this char string which is then assigned to s2. Does this mean that if a constructor function was not specified (unlike here where we have a parameterized constructor) this would not work or does this sort of assingment require a single paramterized constructor? On Tue, Jan 3, 2012 at 12:31 AM, Lucifer sourabhd2...@gmail.com wrote: @above.. This is what i assume is happening ( apart from inherent compiler optimization is any)...Let me know if i m wrong.. when s2=name; is done it should call the overloaded equal to operator.. But, 'name' is not a string object, its basically a char pointer to a const string test.. Now, for simplicity lets assume that name is char array.. Now, given a binary operator, for the operation to take place both the operands ideally should be of the same type... For ex: int a; a = 10.0; Here, 10.0 is double and a is int, for the assignment to work first 10.0 will be converted to int data type and then assigned to a.. In case, the right hand side of a = operator cannot be converted to the left hand side type, then ideally an incompatible assignment shall
Re: [algogeeks] C output????
actually is there any reason as to why same address is returned to the pointer when both pointers(p and q) are initialised to persons unlike when p[] and q[] =persons? On Tue, Sep 6, 2011 at 9:08 AM, Sandy sandy.wad...@gmail.com wrote: String constants (literals) are saved into the .data section of the program, Here is the sample program to show that. if() is essentially comparing the addresses of two pointers which is same. int main() { char *p=persons; char *q=persons; char *r=persons; char *s=persons; printf(%x %x %x %x\n,p,q,r,s); if(p==persons) printf(technical %s,p); else printf(true %s,p); return 0; } - Output: 403021 403021 403021 403021 technical persons On Tue, Sep 6, 2011 at 9:04 PM, sivaviknesh s sivavikne...@gmail.comwrote: main() { char *p=persons; clrscr(); if(p==persons) printf(technical %s,p); else printf(true %s,p); return 0; } ..op : technical persons ..plz explain .. how come it works like an strcmp operation??? -- Regards, $iva -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Sandeep Kumar,* ( Mobile +91-9866507368 *“I believe in smart work, Believe Me”* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Explanation
@Vrashabh: yea the explanation is kinda difficult to follow since f(1,2) is once done first and once is not though the expressions look similarcan u pls explain what decides the order of evaluation here On Mon, Aug 29, 2011 at 6:23 AM, kartik sachan kartik.sac...@gmail.comwrote: see the out put will the help of gcc -E.u will get ur ans -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: String passing
if instead of passing hello directly to function if we passed char array p then this would not show as an error right? and why is this so? is it due to the fact tat p array was not possibly allocated in the read only segment of memory and hence when passed it can be modified by function? so if const string is passed directly what causes the error? On Sat, Aug 27, 2011 at 11:28 AM, sagar pareek sagarpar...@gmail.comwrote: @raj u already mentioned that if we write :- char *p=hello; p[0]='k'; // gives runtime error so if we are passing arguments as modify(char a[],char *b) { . . } main() { . . modify(hello,hi); . . } then its actually char arr[]=hello; char *b=hi; so ofcourse now b[0]='a'; // give u runtime error now u may be confuse about arr[0]='a'; //gives runtime error here i would like to tell you that arr is char pointer not char array you can check by yourself in :- http://www.ideone.com/EQrjj On Sat, Aug 27, 2011 at 10:39 PM, raj kumar megamonste...@gmail.comwrote: monsters are monsters -- Forwarded message -- From: raj kumar megamonste...@gmail.com Date: Sat, Aug 27, 2011 at 10:30 PM Subject: Re: [algogeeks] Re: String passing To: algogeeks@googlegroups.com can't understand what are you trying to say source -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: convert into palindrome
@lucifer: can you please give a small example and explain? Now, all we need to do is sequentially access the list and do the following: Given 2 pairs (xi, yi) and (x i+1, y i+1), We will insert RevStr(yi .. y i+1) , excluding the extreme chars, just before Str(x i+1)... On Fri, Dec 16, 2011 at 4:26 AM, atul anand atul.87fri...@gmail.com wrote: Ignore my previous comment On 16 Dec 2011 17:35, atul anand atul.87fri...@gmail.com wrote: @All : can't we use Levenshtein algorithm to find min addition/deletion.?? On Fri, Dec 16, 2011 at 2:50 PM, top coder topcode...@gmail.com wrote: @Lucifer I have got the intent of your logic. From the algo, We got to know how many characters need to be added. How do you concluded where do you need to add the characters exactly and What characters needs to be added? Also Could you comment on the time and space complexity? On Dec 15, 11:37 am, Lucifer sourabhd2...@gmail.com wrote: Correction: for NAN : N(IT)A + TI + N = NITATIN On Dec 15, 11:33 am, Lucifer sourabhd2...@gmail.com wrote: @topcoder.. String: NITAN RevStr: NATIN LCS ( NITAN, NATIN) = { NIN , NAN } Here all we care about the count which is 2. Hence, 2 additions would be required to convert it into a palindrome.. The possible palindromes would be: for NIN : N + AT + I(TA)N = NATITAN for NAN : N + TI+ A(IT)N = NATITAN On Dec 15, 11:24 am, top coder topcode...@gmail.com wrote: @Mohit Suppose for example String: NITAN LCS(Longest Common Subsequence) : NIN How do you get the palindrome with it? On Dec 15, 3:47 am, Lucifer sourabhd2...@gmail.com wrote: @Mohit I think what he meant is 2* strlen(Input String) - 2* (Length of LCS) On Dec 15, 3:44 am, Mohit kumar lal kumarmohit...@gmail.com wrote: @saurabh-as by the above example LCS of HELLO and its inverse would be LL and how can we form the word HELLOLLEH with it ... and is your ans for the word NITAN is NITATIN ...? On Wed, Dec 14, 2011 at 8:39 PM, saurabh singh saurab...@gmail.com wrote: Find the LCS of string with its reverse On Wed, Dec 14, 2011 at 8:33 PM, top coder topcode...@gmail.com wrote: Given a word, convert it into a palindrome with minimum addition of letters to it. letters can be added anywhere in the word. . for eg if hello is given, result should be hellolleh -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mohit kumar lal rit2009014 IIIT ALLAHABAD contact@9454681805 kumarmohit...@gmail.com mohitkumar...@yahoo.com rit2009...@iiita.ac.inhttp:// profile.iiita.ac.in/rit2009014-Hidequotedtext - - Show quoted text -- Hide quoted text - - Show quoted text - -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview Question
@utkarsh: in yr code it shud be two-- after the swap function and not before for case 2 On Thu, Nov 10, 2011 at 1:25 PM, UTKARSH SRIVASTAV usrivastav...@gmail.comwrote: sorry it was incomplete On Fri, Nov 11, 2011 at 2:53 AM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: one = zero = 0; two = n-1; //n is length of string while(two=one) { switch(a[one]) { case '0' : swap(a[zero],z[one]); one++;zero++;break; case '1' : one++; break; case '2' : two--; swap(a[one],a[two]); } } On Mon, Oct 24, 2011 at 9:50 PM, praveen raj praveen0...@gmail.comwrote: This can be done in O(n).. first shift all the 2's to the right side in O(n)... then again shift 1to the right shift b efore 2's. in O(n)... With regards, Praveen Raj DCE-IT 3rd yr 735993 praveen0...@gmail.com On Mon, Sep 26, 2011 at 6:23 PM, Naren s sweetna...@gmail.com wrote: dutch national flag problem..search in wiki...classical. On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI viharri@gmail.com wrote: You are given a string (consisting of 0's, 1's or 2's) where 0 represents a blue ball, 1 a red ball, and 2 a black ball. Using only swap operations (counting sort not allowed) rearrange the string such that all blue balls are together on one side, followed by all red balls, and then all black balls. You can iterate through the string only once. Eg 102112011 should produce 00122 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Narayanan S,* B.E., C.S.E., (final year), College Of Engineering Guindy, Anna University, Chennai-25. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Interview Question
also I dont think that for case 0 we do not need to have one ++. I guess it fails for this example 2200101 On Mon, Jan 2, 2012 at 5:36 PM, Arun Vishwanathan aaron.nar...@gmail.comwrote: @utkarsh: in yr code it shud be two-- after the swap function and not before for case 2 On Thu, Nov 10, 2011 at 1:25 PM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: sorry it was incomplete On Fri, Nov 11, 2011 at 2:53 AM, UTKARSH SRIVASTAV usrivastav...@gmail.com wrote: one = zero = 0; two = n-1; //n is length of string while(two=one) { switch(a[one]) { case '0' : swap(a[zero],z[one]); one++;zero++;break; case '1' : one++; break; case '2' : two--; swap(a[one],a[two]); } } On Mon, Oct 24, 2011 at 9:50 PM, praveen raj praveen0...@gmail.comwrote: This can be done in O(n).. first shift all the 2's to the right side in O(n)... then again shift 1to the right shift b efore 2's. in O(n)... With regards, Praveen Raj DCE-IT 3rd yr 735993 praveen0...@gmail.com On Mon, Sep 26, 2011 at 6:23 PM, Naren s sweetna...@gmail.com wrote: dutch national flag problem..search in wiki...classical. On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI viharri@gmail.comwrote: You are given a string (consisting of 0's, 1's or 2's) where 0 represents a blue ball, 1 a red ball, and 2 a black ball. Using only swap operations (counting sort not allowed) rearrange the string such that all blue balls are together on one side, followed by all red balls, and then all black balls. You can iterate through the string only once. Eg 102112011 should produce 00122 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Narayanan S,* B.E., C.S.E., (final year), College Of Engineering Guindy, Anna University, Chennai-25. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Doubt in C++
I just have a basic doubt..does the string s1,s2 statement call any default constructor?or is it that it is not performed since parameterised constructor is present? On Wed, Sep 21, 2011 at 1:31 AM, vijay singh vijaysinghb...@gmail.comwrote: It is because of the presence of the single parameterised constructor in the class definition. So, if we are writing the following statement... string s1; s1=test; It'll call the single parameterised constructor. But this only true in the case of single value assignment as in the above statement.. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Sum of Four Numbers in an Array (Amazon)
does this make sense? 1)sort array O(nlogn) 2)keep 4 pointer to last 4 elements of array. At each point in the algorithm we need to ensure than ijkl where i j k and l are positions of the 4 pointers. 3)if(sum of those 4 elements k) there exists no such combination else do binary search with all 4 pointers in nested loop fashion for example if 20 elements in array , say with binary search last pointer starts pointing to position 10. then 3rd last pointer will point to 10/2=5 and 2nd last pointer points to 5/2 =2and first pointer points to 2/2 =1st position. After first pointer is done with binary search, then second pointer moves to next position according to binary search (less than position of 3rd pointer )and then first pointer again does binary search in this new space etc etc...basically it is something like O(logn*logn*logn*logn)...I guess this is less than O(n^3)?? On Sun, Jan 1, 2012 at 10:31 AM, atul anand atul.87fri...@gmail.com wrote: sort(arr); min=arr[0]+arr[1]+arr[2]+arr[3]; max=arr[n-1]+arr[n-2]+arr[n-3]+arr[n-4]; for(i=0;in-3;i++) { a=arr[i]; k=i+1; l=n-1; m=n-2; while(kl) { b=arr[k]; c=arr[l]; d=arr[m]; if(a+b+c+d == num) { printf(\nNumber found (%d + %d + %d + %d ) = %d,a,b,c,d,num); flag=1; break; } else if(a+b+c+d num) { l--; m--; } else { k++; } } if(flag) break; } complexity = O(N^2); -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: given a stream of numbers FIND MEDIAN
@lucifer: can you explain to me in the current median calculation why if there is a Diff =1 or -1 you are using M and top(maxh) or M and top(minh) for median calculation. If the number of elements from the stream so far is odd then median is just one element and not average of 2 elements right? On Fri, Dec 16, 2011 at 2:06 AM, Lucifer sourabhd2...@gmail.com wrote: @sangeeta I think your question is, given an input stream of nos., at any random time, we need to find what's the current median. For eg- say 4 nos have been read till now, hence, whats the median in those 4 nos. Say now, 7 nos have been read till now from the stream so which is the current median.. Am i ryt? If my above understanding is correct.. then the following approach might work.. Take a variable to store the actual median, say M. Take 2 heaps, one min-heap and one max heap say, minH and maxH. Take a variable to store the difference in the no. of elements stored by both the heaps i.e { count(maxH) - count(minH) } We need to maintain the following constraint :- The size of minH and maxH shouldn't differ by more than one. Say, currently the no. of elements scanned is odd hence, the storage state will be as follows: 1) sizeof minH = size of maxH 2) M will give u the median. Say, currently the no. of elements scanned is even hence, the storage state will be as follows: 1) abs(sizeof maxH - size of minH) = 1 2) M will give u the median. 3) Ideally there are 2 median elements in this case, hence to get the second median get the top element of the heap which has more no. of elements. i.e If sizeof minH sizeof maxH, then top(minH) is the other median, apart from M, else top(maxH) is the other median. Algorithm : Say, the difference of the size of the heaps is stored in variable, Diff = size(maxH) - size(minH) // Diff can have values -1, 0, 1.. 0- size(minH) = size(maxH), -1 - size(minH) = size(maxH) + 1 1 - size(maxH) = size(minH) + 1 Get the no. from the stream, say X... a) If M is empty then put M = X; b) Else, If (Diff == 0) { If (M= X) Add X to maxH; Diff = 1; else Add X to minH; Diff = -1; } else If (Diff == -1) { if (M=X) Add X to maxH; else { Add M to maxH; If (X = top(minH)) M = X; else { M = top(minH); top(minH) = X; heapify for top(minH); } } Diff = 0; } else { if (X=M) Add X to minH; else { Add M to minH; If (X = top(maxH)) M = X; else { M = top(maxH); top(maxH) = X; heapify for top(maxH); } } Diff = 0; } To get the current median: if (Diff == 0) Current median = M; else if (Diff == -1 ) Current median = top(minH) and M; else Current median = M and top(maxH); On Dec 16, 12:50 pm, arvind kumar thebossku...@gmail.com wrote: Hi,have a look at this,n revert back in case of doubts: http://www.cs.cmu.edu/~avrim/451/lectures/lect0903.pdf On Fri, Dec 16, 2011 at 12:56 PM, Sangeeta sangeeta15...@gmail.com wrote: You are given a stream of numbers which can be positive or negative. You are required to provide an operation FIND MEDIAN..which when invoked should be able return the median of the numbers in stream (in sorted order) in O(1) time. -- 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 more options, visit this group athttp:// groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV
@atul: can you explain what this is doing? for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } when u do tree reversal I see that child points to parent( basically direction reversed). Now if 1 /|\ 234 //\ 5 6 7 /\ 89 in the last iteration along leftmost path , pointer to 8 is returned(pre) whose child is then assigned as 5 using pre-children[0]=root if 5 had another child say 'x' then after x is returned from thr recursive call, u wud assign pre-children[1]=root where root is pointer to 5 here..but 8 and x have only one child which is 5 and indexes used for each are 0 and 1 instead of just 0..am i understanding it wrongly? On Wed, Dec 21, 2011 at 8:37 PM, atul anand atul.87fri...@gmail.com wrote: adding one more check :- this one is updated node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; break; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { if(root-children[i]!=NULL) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } } return root; } On Thu, Dec 22, 2011 at 9:35 AM, atul anand atul.87fri...@gmail.comwrote: adding break to first loop...just to avoid unnecessary iterations. if (root-children[i]!=NULL) { flag=1; break; } end for On Wed, Dec 21, 2011 at 10:59 PM, atul anand atul.87fri...@gmail.comwrote: @shashank: yeah here is the algo , please me know if you find any bug:- node *Reverse(node *root,node *pre) { flag=0; for i=0 to n if (root-children[i]!=NULL) { flag=1; } end for if( ! flag) { add root to the list; return root; } for(i=0;in;i++) { pre=reverse(root-children[i],NULL); if(pre) { pre-children[i]=root; } } return root; } On Wed, Dec 21, 2011 at 1:08 PM, WgpShashank shashank7andr...@gmail.com wrote: @atul,, yeah , but can you write some proper psuedo code/ Algorithm then we can discus more about test cases. Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VPZpHM8D_WcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Return index of first mismatch bracket ( or )
@shady: I guess first mismatch means the innermost open brace that doesnt have a close brace. U cannot know that the first brace does not have a closing one unless u look at the entire string. On Tue, Dec 20, 2011 at 9:23 AM, shady sinv...@gmail.com wrote: ( ( ) ( ( ) ( ( ) ) ( ) for this SAMM faulty index is 0, because the first bracket has itself found no matching @atul ( ( ( () ) ) for this first bracket is faulty as it couldn't find a closing bracket, , , you can keep a stack with map as element stack mapint, char mapint, char where integer is the index of the bracket, which is stored as char idea is similar to don's. On Tue, Dec 20, 2011 at 10:42 PM, atul anand atul.87fri...@gmail.comwrote: there are multiple mismatch or only one mis-match in the input string. if the given string as below :- ( ( ( () ) ) - for this is missing match is for 1st , 2nd or 3rd bracket. what would be the answer for this. On Tue, Dec 20, 2011 at 8:10 PM, zeroByZero shri.nit...@gmail.comwrote: In a given string arrary arr[] = ((()()) or any other string return index for which no match is found as for this example is index 0 and for ()()()(() is index 6 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] find numbers if pair wise sums are given
how is the case taken of when 2 pairs add to the same sum?... On Tue, Dec 13, 2011 at 11:35 AM, atul anand atul.87fri...@gmail.comwrote: hmmm i guess i screwed by taking least element as a part of the output set directly. On Wed, Dec 14, 2011 at 12:57 AM, sayan nayak sayanna...@gmail.comwrote: @atul: Suppose the input is :(7,8,9) So output should be (3,4,5) then ur approach is not giving the answers.. Regards, Sayan On Tue, Dec 13, 2011 at 11:51 PM, atul anand atul.87fri...@gmail.comwrote: i am not sure , but this came to me when i first read it here is the idea:- given : 4 5 7 10 12 13 4 should be there boz it is the least. next is 5 , 5-4 =1 which is less that 4 , so 1 should be there next is 7 , 7-4 = 3 which is less than 4 , so 3 should be there next is 10 , 10-4 = 6 which is greater then 4 , so add previous found elements i.e 1,3,4 add them 1+3+4 = 8 , add 1 to 8 = 9 now check ,can we use this number(i.e 9 ) and previous found elements ( 1,3,4) to form 10 ( 9 +1) : yes - so 9 should be there next is 12 , 12-4 = 8 ( but now greatest element among 1,3,4,9 is 9) and 8 9 ,so skip; next is 13 , 13-4 = 9 same reason for skipping as for number 12 before. On Tue, Dec 13, 2011 at 10:28 PM, top coder topcode...@gmail.comwrote: If pairwise sums of 'n' numbers are given in non-decreasing order identify the individual numbers. If the sum is corrupted print -1 Example: i/p: 4 4 5 7 10 12 13 o/p: 1 3 4 9 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] median from continuous stream
Hi to find running median from a stream of random generated numbers I have heard of the 2 heap ( min and max heap ) solution but I fail to understand it...could someone please explain with a small example or so ?? thanks! -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Searching In a large file
can someone give me a short explanation of Dave solution? I understand that a[n%10] 1 is trying to find the bin which has less than what maximum numbers it can hold and the bin is such that all numbers counted in this have the same remainder when divided by 10. I do not get the a[n/10] part after that ..wat is that trying to say? On Sat, Oct 29, 2011 at 10:42 AM, yq Zhang zhangyunq...@gmail.com wrote: Given the SSN number is 9 digit number, the total space of possible numbers are 1000million. So I think Dave's solution works. On Sat, Oct 29, 2011 at 8:47 AM, bharat b bagana.bharatku...@gmail.comwrote: @Dave Your solution works if the total no.of records(ssn numbers) is 1000 million. But the question states that there are only 300 million numbers. I think some modification is needed to your answer. Correct me if i am wrong. On Fri, Oct 28, 2011 at 2:04 AM, Dave dave_and_da...@juno.com wrote: @Shiva: Using an integer array a[10], initialized to 0, read through the file and for each number n, increment a[n%10]. At the end of the file, find any k such that a[k] != 1. Then read through the file again. For any number n such that n%10 == k, set a[n/ 10] = -1. At the end of file, find any j 1 such that a[j] = 0. Then 10 * j + k is a number that is missing from the file. Dave On Oct 27, 10:25 am, shiva@Algo shiv.jays...@gmail.com wrote: Given a file containing roughly 300 million social security numbers(9-digit numbers), find a 9-digit number that is not in the file. You have unlimited drive space but only 2megabytes of RAM at your disposal. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] finding anagrams in file
Hi all, How to find all the anagrams in a large file containing n words and max length of a word is m letters?? so if file contains add dad abc ced cba it shud say adc dad are anagrams and abc cba are anagrams. time needed is 0(nlogn) -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: finding anagrams in file
Hmm I see but if there are m max letters in each word and there are n words in the file, then each word sort is O(mlogm) and for n words so wont it be O(nmlogm)? On Tue, Oct 18, 2011 at 12:55 PM, WgpShashank shashank7andr...@gmail.comwrote: Sort the all the string , Calculate hash-value , if the two has same hash vale they have to be anagram. put in group on the basis of anagram. leme know if i missed anything ? TC O(nlogm) n =number of words m is length of max string Shashank CSE,BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/FvPZTBiPMHgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: finding anagrams in file
also what would be a suitable hash function for the string? On Tue, Oct 18, 2011 at 1:21 PM, Arun Vishwanathan aaron.nar...@gmail.comwrote: Hmm I see but if there are m max letters in each word and there are n words in the file, then each word sort is O(mlogm) and for n words so wont it be O(nmlogm)? On Tue, Oct 18, 2011 at 12:55 PM, WgpShashank shashank7andr...@gmail.comwrote: Sort the all the string , Calculate hash-value , if the two has same hash vale they have to be anagram. put in group on the basis of anagram. leme know if i missed anything ? TC O(nlogm) n =number of words m is length of max string Shashank CSE,BIT Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/FvPZTBiPMHgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] complement
Hi all, When I take negation of an integer in C, 0 is displayed as -1 ~5 is displayed as -6. Can some one tell me the logic of how this conversion is happening in C? Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: complement
Thanks Dave , appreciate it On Sun, Sep 18, 2011 at 7:15 PM, Dave dave_and_da...@juno.com wrote: @Arun: This is the way two's complement arithmetic works. For any x, - x = ~x + 1. This says that to negate a number, complement it and add 1. Technically speaking, two's complement is a weighted code. Each bit position has a certain weight that is added in if the bit in that position is a 1. Counting from the right (low-order bit), the weights are 1, 2, 4, 8, ..., -2^(n-1), where n is the number of bits in the integer. Thus, for example, for 8 bit integers, the weights are 1, 2, 4, 8, 16, 32, 64, and -128. Let bi be the ith bit of the number, counting from the right with the low order bit being bit 0. Let wi be the weight of the ith bit. Then the value of the number is V = sum from i = 0 to n-1 of (bi * wi). The value of the complement of the number is ~V = sum from i = 0 to n-1 of ((1 - bi) * wi), where 1 - bi is the complement of bit i, i.e., ~bi. Then V + ~V = sum from i = 0 to n-1 of wi since bi cancels -bi for every i. The sum of the weights is -1. Thus, V + ~V = -1, from which -V = ~V + 1. Dave On Sep 18, 5:26 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: Hi all, When I take negation of an integer in C, 0 is displayed as -1 ~5 is displayed as -6. Can some one tell me the logic of how this conversion is happening in C? Arun -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Remove all Duplicates Words
@anup: can u provide a sort of pseudocode as to how ur code is O(n)?firstly u need to find out which word might have a repetition. so u compare first character of first word with all the other first characters.if there is not repetition , then u have to compare first character of second word with all the first character of words ahead of it and so on till u might sense a repetition.once u find a repetition u shift all the remaining words over the duplicated word.this is O(n) again. so are u doing this with a lot of pointers or how is that u keep it O(n) overall? On Thu, Aug 25, 2011 at 9:56 AM, sagar pareek sagarpar...@gmail.com wrote: thanks ankur khurana @dave May be u never did any mistake in posting and reading the problems. But dont think urself superior. Yeah i did mistake in reading the question so u must either ignore it or request me to not repeat it in future. You are behaving like its my daily routine of doing such kind of things. On Thu, Aug 25, 2011 at 11:56 AM, Anup Ghatage ghat...@gmail.com wrote: Actually, this method will be O(n) for any number of occurrences of a single word, but It will go into O(n^2) for multiple occurrences of multiple words. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: C doubt
thanks guys! On Wed, Aug 24, 2011 at 6:37 PM, Don dondod...@gmail.com wrote: Yes, the memory provided by malloc will not be in the structure. Only the pointer to that memory will be in the structure. The size of a struct is defined at compile time, so it can't be dynamically sized at run time. struct junk { int size; int *data; }; Somewhere in the code: struct junk myJunk; myJunk.size = n; myJunk.data = (int *)malloc(n * sizeof(int)); for(i = 0; i n; ++i) myJunk.data[i] = i; That should work for values of n which your memory can support. sizeof(struct junk) is eight bytes even if it contains a pointer to a million integers. Don On Aug 24, 11:04 am, sagar pareek sagarpar...@gmail.com wrote: See if we use dynamic memory allocation then still the size of pointer will be 4 bytes only Mean that int* pointer still have the size equals to pointer ... malloc only returns new alloted memory which is now only *pointed *by that pointer check this out :-http://www.ideone.com/20ayq On Wed, Aug 24, 2011 at 8:10 PM, Don dondod...@gmail.com wrote: If you are working in C++, stl has a vector container class which will do this. Otherwise, declare an integer pointer in the struct and use malloc to allocate memory for it. Then you can use it like an array. Don On Aug 23, 11:51 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: say that you have a structure with some fields of known size and unknown size.For example, a char, an integer and an integer array.I do not know the size of the integer array until the user mentions the number of bytes he needs this integer array to cover in the command line as an argument.Is it possible to have a structure with an integer dynamic array? Arun -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] C-hexadecimal doubt
Hi all, I need to store a hexadecimal value in C( which would be used as a request type in a network) of around 4digits( or 16 bits-2 bytes ) in a packet structure.If my system keeps 4 bytes for an integers, is it necessary that I have to declare the hex value as of type short int or so, so that it takes up only 2 bytes in my packet ? What if it was required to have a hex value of 3 bytes or so? How could i store it then? Also if hex value was to be of a multiple of 4 bytes would i need to use something like an integer array to store them or a float maybe? thanks! -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: C-hexadecimal doubt
@don: so if a 16bit value is put into a 32 bit field and i need to read the value, do i need to read last 16 bits only somehow ? On Wed, Aug 24, 2011 at 8:22 PM, Don dondod...@gmail.com wrote: It is most common to use 4 bytes to store an integer value, even if the full range will not be used. There is no problem putting a 16-bit value into a 32-bit field. The only case where this is not true is when memory is extremely limited and you need to pack as much into every word as possible. Do be aware that most structures are word- aligned, so to actually save memory you must have several adjacent elements in the structure which can be combined into one word. Don On Aug 24, 1:07 pm, Arun Vishwanathan aaron.nar...@gmail.com wrote: Hi all, I need to store a hexadecimal value in C( which would be used as a request type in a network) of around 4digits( or 16 bits-2 bytes ) in a packet structure.If my system keeps 4 bytes for an integers, is it necessary that I have to declare the hex value as of type short int or so, so that it takes up only 2 bytes in my packet ? What if it was required to have a hex value of 3 bytes or so? How could i store it then? Also if hex value was to be of a multiple of 4 bytes would i need to use something like an integer array to store them or a float maybe? thanks! -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] C doubt
say that you have a structure with some fields of known size and unknown size.For example, a char, an integer and an integer array.I do not know the size of the integer array until the user mentions the number of bytes he needs this integer array to cover in the command line as an argument.Is it possible to have a structure with an integer dynamic array? Arun -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Puzzle
@DK:if L is married to M according to you finally , then what does the third if then statement according to you mean when it is given that if L is not married then M is married? On Fri, Aug 19, 2011 at 10:35 PM, Dave dave_and_da...@juno.com wrote: @DK: What in the statement of the problem led you to believe that these were if-then statements? Dave On Aug 19, 3:15 pm, DK divyekap...@gmail.com wrote: Note that in the answer above, the table given is of the form: If condition is truethen what predicate is true ----- M - married N - not married N - married L - not married L - not married M - married -- DK http://gplus.to/divyekapoorhttp://twitter.com/divyekapoorhttp://www.divye.in -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] duplicate elements
in an earlier post there was a discussion in which a person had asked to find the duplicate element in an array of integers in o(n) time and o(1) space... there was a solution using xor that was provided if all numbers in the range from 1-n with one repeating element were present in the array. anyways, what is the effective method to find 1) given an array with any set of positive integers , to find the duplicated element? 2)if array has negative and positive integers now, would the algo differ? 3)to find an element that has been repeated k times? -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: print all paths which sum up to a value.
@mac: just to clear my understanding, u need to print paths that sum up to a Value which means the value of the nodes in a path is added right to see if it satisfies this Value? does the value at each node have any relevance as such? I mean can it be any value at any node or does value at a node satisfy something like a bst property? On Fri, Aug 19, 2011 at 2:04 PM, anshu mishra anshumishra6...@gmail.comwrote: start from leaves.(leaves have possible sum only its value) go up step by step save all the possible sums on that node. for example if left node has possible sums( 4, 6, 7 ,13) and right node has possible sums (3, 5, 9); and node itself value has 5 than this node all possible sums will be (8, 10, 11, 12, 14, 18) till u reach the root node u have all possible sums at each node. search ur desired sum node in the tree track all possible path for that sum(u have to just only downside of the tree). -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: calculate a/b without using ‘*’, ‘/’’ and ‘%’
@dave: actually how did u get the approach to this? I mean why did u have to do the q|=1 in the if(a=b) condition and q=1 always in the loop? On Fri, Aug 19, 2011 at 1:46 PM, Sanjay Rajpal tosanjayraj...@gmail.comwrote: @Shashank : Would you throw some light on how you determined the complexity ? *Regards Sanju Happy to Help :)* On Fri, Aug 19, 2011 at 2:36 AM, WgpShashank shashank7andr...@gmail.comwrote: We can use bit logic to reduce the time complexity to O(logn) where n is Quotient Algorithm will be as follow as we know 1. Left shifting an unsigned number by 1 multiplies that number by 2. 2. Right shifting an unsigned number by 1 divides that number by 2. Therefore the procedure for the division algorithm, given a dividend and a divisor . core logic will be to left shift (multiply by 2) untill its greater then dividend , then continue this routine with the the difference between the dividend and divisor and divisor till the point where dividend is less than divisor or their difference is zero. Lets see one example: dividend=23 divisor=3 then left shift for 3 i.e 3 will converted to3, 6,12,24,… since 12 23 hence now dividend is 11 and quotient in 4(two time shift operation) now again 3,6,12.. 611 hence dividend is 11-6=5 and quotient =4+2=6 now only 35 hence remainder =2 quotient =6+1=7 so answer. Time Complexity O(logn) Number of bits in Quotient Correct me if anything wrong *Thanks Shashank Mani Computer Science Birla Institute of Technology Mesra* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/VszScC-sOfoJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: longest repeated substring
am just asking but how can u get all possible substrings in O(n square) time when there are 2 power N of them actually? On Thu, Aug 18, 2011 at 4:20 PM, DheerajSharma dheerajsharma1...@gmail.comwrote: O(n^2) i guess.. We can save all possible substrings..(in two loops it can be done) in a hash map..as key..and the value as COUNT..then we can..search for the most occurring substring!! u said for non - efficient ;) On Aug 18, 6:07 pm, MAC macatad...@gmail.com wrote: A string can have many sub-strings inside it . find the longest substring which is repeated maximum number of times. in case of 2 options repeated same number of times , largest one needs to be ouput and in case same length and same number of times repeated , anyone can be outputted. abcdefcbcdfbcdefef has bcd and ef repeated multiple times but bcd count trie apraoch is fine , but in interview difficult to code ,.so definately some other solution is requested . please also give non-efficient , but easy to code solution if any -- thanks --mac -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: calculate a/b without using ‘*’, ‘/’’ and ‘%’
@dave: in your algorithm, I have a doubt in the second loop( for loop ). q=0 initially so the first q1 stays zero and then q|=1 makes q=1 now. 1 then becomes x 2 and then again with the OR 2 becomes 3. 3 becomes 6 and with the OR 6 becomes 7. for example if i need to do 24/3, according to the code k=3 after while loop and then the for loop terminates with q as 7 as i mentioned the steps above.Have i got the understanding of the code wrong? On Thu, Aug 18, 2011 at 7:18 PM, Dave dave_and_da...@juno.com wrote: @Dheeraj: What about it? It doesn't give the quotient. What is it supposed to do? Dave On Aug 18, 11:06 am, DheerajSharma dheerajsharma1...@gmail.com wrote: wat about shifting 'a' right by floar(log2(b)) and adding 1 to it.. On Aug 18, 8:48 pm, aditya kumar aditya.kumar130...@gmail.com wrote: how abt subtracting . like a=a-b till a becomes zero . no of times subtraction is done is the answer . correct me if i am wrong ! On Thu, Aug 18, 2011 at 8:59 PM, Dave dave_and_da...@juno.com wrote: @Radha: You could simulate long division. It would look something like this: int divide(int a, int b) { int i, k=0, q=0, s=1; // error checking if( b == 0 ) return 0 // return 0 for division by zero // handle signs if( a 0 ) { a = -a; s = -1; } if( b 0 ) { b = -b; s = -s; } // quick cases if( a b ) return 0; if( a == b ) return s; // shift divisor to align with dividend while( b a ) { b = 1; ++k; } // perform k steps of long division in binary for( i = 0 ; i k ; ++i ) { q = 1; b = 1; if( a b ) { a -= b; q |= 1; } } // apply sign to result if( s 0 ) q = -q; return q; } Dave On Aug 18, 8:56 am, radha krishnan radhakrishnance...@gmail.com wrote: how to do using BIT manipulation ? -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] reason
@programming love:I can understand what u say but my doubt is that for the first output which is 2, according to your example, p has address 10 which it points to.And as u say int * tends to dereference 2 bytes so that wud be now 10 and 11.finally char * takes only 1 byte so why is value at 11 address printed( i mean 02) and not value at 10 address( 00) similarly for the second output where u say p+1 goes from 10 to 11 due to char type.when u do int* u say it dereferences 11 and 12. so then when char * is done finally why does it print the one at 12 and not 11? please correct my understanding if wrong On Mon, Aug 15, 2011 at 10:44 AM, programming love love.for.programm...@gmail.com wrote: The internal representation of array is this: suppose that the address starts from decimal number 10 and integer occupies 2 bytes 10- 0002 ( num 2 in hex) 12- 0003 ( num 3 in hex) 14- 0004 ( num 4 in hex) Now p points to address 10 and is type char. (Even after type casts) p+1 will increment address by 1 byte (since it's char). p will now point to 11 (int *) will say that when de-referenced 2 bytes should be extracted. So the 2 bytes extracted are 11, 12. Numbers in these bytes are 02 and 00 10- 00*02* ( num 2 in hex) 12- *00*03 ( num 3 in hex) 14- 0004 ( num 4 in hex) now (char *) says extract 1 byte for me. The extracted byte is 00. Hence 0 is printed *Correct me if i am wrong.* -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
so according to the discussions above input should start with and end with but also there is a thing that input is accepted until is encountered.Is not this contradicting? On Sun, Aug 14, 2011 at 3:13 PM, shady sinv...@gmail.com wrote: no, input should start and end with a On Sun, Aug 14, 2011 at 6:38 PM, aditya kumar aditya.kumar130...@gmail.com wrote: the input should start with \ and end with \ . in between you can take any string . On Sun, Aug 14, 2011 at 6:35 PM, Poised~ dip10c...@gmail.com wrote: small correction in my above explanation the %[^\] will accept the input till it doesn't encounter a Missed the ^ (XOR) operation completely. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/Tn6jNNCGeWoJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c question!
hmm ya am sorry abt that..what abt the first part i mentioned...how is it (nodeptr*)malloc according to you (which is creating a pointer to a pointer type nodeptr )rather than just nodeptr which is a pointer to structure? how to get size of structure as such in this case? On Thu, Aug 11, 2011 at 7:04 AM, siddharth srivastava akssps...@gmail.comwrote: (sizeof(struct)); ?? That doesn't makes sense. Size of struct is what ?? you need the size of your structure with the variables you have declared in it. cos malloc returns pointer to memory block and nodeptr itself is a pointer and you have used nodeptr* further? On Tue, Aug 9, 2011 at 6:32 PM, siddharth srivastava akssps...@gmail.com wrote: @sidharth: thanks a lot for correcting me :) @aditya : no. there was some mistake; in the code i pasted above it's giving segmentation fault. Is it cause i'm initializing h without using malloc?? Please throw light on this problem Pointer points to a location in memory. You can't use h without making h to reference to some area in memory. And in the following code char *s; scanf(%s, s); why isn't it possible to store a string in s?? Please explain both concepts. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Siddharth Srivastava -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Siddharth Srivastava -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Jumping Puzzle
I did not get the optimal solution part..how is that u jump 1 to index 1? On Thu, Aug 11, 2011 at 10:07 AM, Algo Lover algolear...@gmail.com wrote: Given an array, start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in the array. Optimum result is when you reach the goal in minimum number of jumps. For ex: Given array A = {2,3,1,1,4} possible ways to reach the end (index list) i) 0,2,3,4 (jump 2 to index 2, then jump 1 to index 3 then 1 to index 4) ii) 0,1,4 (jump 1 to index 1, then jump 3 to index 4) Since second solution has only 2 jumps it is the optimum result. My solution is for any index i loop from i to i + A[i] find an index j where (j + A[j]) is maximum for all j. make i=j; This solution in O(n) i suppose coz we are picking each element twice in the worst case. I have read a O(n^2) DP solution for this problem.Is there any case where my approach will fail ? -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c question!
@siddarth: should not the statement you mentioned above as nodeptr h = (nodeptr*)malloc(sizeof(nodeptr*)); be nodeptr h =(struct*)malloc(sizeof(struct)); ?? cos malloc returns pointer to memory block and nodeptr itself is a pointer and you have used nodeptr* further? On Tue, Aug 9, 2011 at 6:32 PM, siddharth srivastava akssps...@gmail.comwrote: @sidharth: thanks a lot for correcting me :) @aditya : no. there was some mistake; in the code i pasted above it's giving segmentation fault. Is it cause i'm initializing h without using malloc?? Please throw light on this problem Pointer points to a location in memory. You can't use h without making h to reference to some area in memory. And in the following code char *s; scanf(%s, s); why isn't it possible to store a string in s?? Please explain both concepts. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Siddharth Srivastava -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] simple doubt
@jiten: that staement means pa is a pointer to 3 ints not an array of pointers.. int *pa[3] means it is an array of pointers On Fri, Aug 5, 2011 at 8:44 PM, Jiten j.playe...@gmail.com wrote: (*pa)[3] ;// pa is array of pointers to int type; so pa = arr; doesn't make any sense ,bcoz arr represents the base address of it(address of arr[0]). and pa represent the address of pa[0](which hold a pointer). I hope it's clear now -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] output?
@sandeep: so the statement becomes if(ch=0) since printf returns integer 0...whats does this mean now actually?0 is ascii for NULL and so ch is assinged to null? I am slightly confused.. On Tue, Aug 9, 2011 at 7:04 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: @all sorry i give wrong explanation by mistake..:P :P printf() returns no if characters.. in this case returns 0 . which is assigned to ch so in ch 0 is stored and 0 is the ascii value of null character when we using ch in --- if (ch) -- it will reduce to if(0) -- as 0 is the ascii value of null character so the output it doesn't matter On Tue, Aug 9, 2011 at 10:28 PM, Dipankar Patro dip10c...@gmail.comwrote: o/p: It doesn't matter Reason: printf() returns the number of characters printed to screen. since printf() will return 0, hence the *else* is selected. On 9 August 2011 22:25, siddharth srivastava akssps...@gmail.com wrote: On 9 August 2011 22:20, tech rascal techrascal...@gmail.com wrote: #includestdio.h int main() { char ch; if((ch=printf())) printf(it matters); else printf(it doesn't matter); return 0; } It doesn't matter what will b the output?? -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Siddharth Srivastava -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] problem regarding output??
@ankit: does that mean that after the compiler is informed that the void pointer will point to integer witht he typecast statement and then we point it to some other type , it will be an error? i mean after that typecast statement, if i do char a; k=a;is it wrng? On Tue, Aug 9, 2011 at 2:06 PM, ankit sambyal ankitsamb...@gmail.comwrote: The typecasting tells the compiler that the void pointer is now pointing to an integer and when we use this pointer to access the integer it takes value from 4 bytes. But when we try to increment that pointer, it will point to the next byte. Try taking k as pointer to double instead of void, u will c the same result. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Probability Puzzle
@dave: yes it seems so that 17/18 is correct...I deduced it from the cond prob formula.. I have a minor doubt in general why prob( 2nd toss is a head given that a head occurred in the first toss ) doesnt seem same as p( head in first toss and head in second toss with fair coin) +p(head in first toss and head in second toss with unfair coin)? is it due to the fact that we are not looking at the same sample space in both cases?i am not able to visualise the difference in general..this is also the reason why most of the people said earlier 17/80 as the answer moreover, if the question was exactly the same except in that it was NOT mentioned that heads occurred previously , what would the prob of getting a head in the second toss? would it be P( of getting tail in first toss and head in second toss given that fair coin is chosen) +P( of getting head in first toss and head in second toss given that fair coin is chosen) +P( getting heads in first toss and heads in second toss given that unfair coin is chosen) ? this for any toss turns out to be 3/5 can u explain the logic abt why it always gives 3/5? On Tue, Aug 9, 2011 at 7:37 AM, raj kumar megamonste...@gmail.com wrote: plz reply am i right or wrong -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Paypal interview Questions
@saurabh: are u referring to bit map sort? On Mon, Aug 8, 2011 at 5:51 PM, saurabh singh saurab...@gmail.com wrote: If you limit the magnitude of numbers,it is On Mon, Aug 8, 2011 at 9:02 PM, siva viknesh sivavikne...@gmail.comwrote: is there any possible solution for O(1) space and O(n) time for unsorted array? On Aug 7, 11:45 am, Amol Sharma amolsharm...@gmail.com wrote: @raghvan: take care of space complexityyou are using extra space that too O(n) in worst case... can be done in O(nlogn) else it can be done in O(n) if the given array is sorted in two traversals !! -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Sun, Aug 7, 2011 at 11:35 AM, programming love love.for.programm...@gmail.com wrote: So is q 1 a C++ question?? On Sun, Aug 7, 2011 at 11:27 AM, hary rathor harry.rat...@gmail.com wrote: no c doesn't -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Probability Puzzle
@don: i too get yr answer 17/18 using conditional probability...does that make sense??i guess this is first new answer lol On Mon, Aug 8, 2011 at 9:29 PM, Don dondod...@gmail.com wrote: The answer is 17 in 18, because flipping 5 heads in a row is evidence that the probability is high that we have the coin with two heads. Don On Aug 7, 12:34 pm, Algo Lover algolear...@gmail.com wrote: A bag contains 5 coins. Four of them are fair and one has heads on both sides. You randomly pulled one coin from the bag and tossed it 5 times, heads turned up all five times. What is the probability that you toss next time, heads turns up. (All this time you don't know you were tossing a fair coin or not). -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Probability Puzzle
@shady: 3/5 can be the answer to such a question: what is prob of getting head on nth toss if we have 4 coins fair and one biased...then at nth toss u choose 4/5 1/5 prob and then u get 3/5 @shady , don: i did this: P( 6th head | 5 heads occured)= P( 6 heads )/ P( 5 heads) answr u get is 17/18..i cud be wrong please correct if so On Mon, Aug 8, 2011 at 10:45 PM, shady sinv...@gmail.com wrote: answer is 3/5. 17/80 is the answer for 6 consecutive heads. On Tue, Aug 9, 2011 at 2:07 AM, Don dondod...@gmail.com wrote: Consider the 5 * 64 possible outcomes for the selection of coin and six flips, each one happening with equal probability. Of those 320 possible outcomes, 4*62 are excluded by knowing that the first 5 flips are heads. That leaves 64 outcomes with the rigged coin and 2 outcomes with each of the fair coins, for a total of 72 outcomes. 68 of those are heads, so the answer to the puzzle is 68 of 72, or 17 of 18. Don On Aug 8, 2:36 am, Shachindra A C sachindr...@gmail.com wrote: @brijesh *first five times* is mentioned intentionally to mislead i think. I vote for 3/5. Moreover, 17/80 doesn't make sense also. Plz correct me if I am wrong. On Mon, Aug 8, 2011 at 12:06 PM, sumit gaur sumitgau...@gmail.com wrote: (3/5) On Aug 7, 10:34 pm, Algo Lover algolear...@gmail.com wrote: A bag contains 5 coins. Four of them are fair and one has heads on both sides. You randomly pulled one coin from the bag and tossed it 5 times, heads turned up all five times. What is the probability that you toss next time, heads turns up. (All this time you don't know you were tossing a fair coin or not). -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards, Shachindra A C -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Question
would u mind giving a short explanation of yr code too if possible? On Thu, Aug 4, 2011 at 5:38 PM, Apoorve Mohan apoorvemo...@gmail.comwrote: I think this should worktell me if this works... void longest_0_1_substring(char *str) { int size=0,count=0,max=0,pos=0,prev=0,prev_pos=0,ptr=0,i=0,j=0; while(*str++) size++; str -= (size + 1); while(isize) { for(j=i;(j size) (str[j]==str[j+1]);++j) count++; count++; if(ptr 1) { if(count = prev) { if(prev max) { max = prev; pos = prev_pos; } } else { if(count max) { max = count; pos = i - prev; } } } prev = count; prev_pos = i; i += count; ++ptr; count = 0; } printf(substring starts at position %d and is of size %d .,pos,max); } On Thu, Aug 4, 2011 at 6:25 PM, himanshu kansal himanshukansal...@gmail.com wrote: okie...can someone do it in O(n) space...bt time shld be linear only On Thu, Aug 4, 2011 at 2:13 AM, Prakash D cegprak...@gmail.com wrote: O(1) space is t hard for this task On Thu, Aug 4, 2011 at 12:55 AM, payel roy smithpa...@gmail.com wrote: Is there any solution for the above? On 3 August 2011 21:09, coder coder i.code.program...@gmail.comwrote: ya amazon will be visiting our campus within few days -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Himanshu Kansal Msc Comp. sc. (University of Delhi) -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards Apoorve Mohan -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Question
by the way doesnt it look like an O(n^2) algo? On Fri, Aug 5, 2011 at 10:53 AM, Arun Vishwanathan aaron.nar...@gmail.comwrote: would u mind giving a short explanation of yr code too if possible? On Thu, Aug 4, 2011 at 5:38 PM, Apoorve Mohan apoorvemo...@gmail.comwrote: I think this should worktell me if this works... void longest_0_1_substring(char *str) { int size=0,count=0,max=0,pos=0,prev=0,prev_pos=0,ptr=0,i=0,j=0; while(*str++) size++; str -= (size + 1); while(isize) { for(j=i;(j size) (str[j]==str[j+1]);++j) count++; count++; if(ptr 1) { if(count = prev) { if(prev max) { max = prev; pos = prev_pos; } } else { if(count max) { max = count; pos = i - prev; } } } prev = count; prev_pos = i; i += count; ++ptr; count = 0; } printf(substring starts at position %d and is of size %d .,pos,max); } On Thu, Aug 4, 2011 at 6:25 PM, himanshu kansal himanshukansal...@gmail.com wrote: okie...can someone do it in O(n) space...bt time shld be linear only On Thu, Aug 4, 2011 at 2:13 AM, Prakash D cegprak...@gmail.com wrote: O(1) space is t hard for this task On Thu, Aug 4, 2011 at 12:55 AM, payel roy smithpa...@gmail.comwrote: Is there any solution for the above? On 3 August 2011 21:09, coder coder i.code.program...@gmail.comwrote: ya amazon will be visiting our campus within few days -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Himanshu Kansal Msc Comp. sc. (University of Delhi) -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards Apoorve Mohan -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] max product of a subarray
it is difficult to read code and understand but based on the logic u mentioned in 3 points i just want to know if u also have taken care of the case where u have zero points in the array and as u say find each product around 0 points, do u check within each subarray around the zero point if the number of negative numbers is even or odd there? in case u have cool but it takes time to sit and understand someone else's code hence am just asking On Thu, Aug 4, 2011 at 5:58 PM, Thayumanavar S thayum...@gmail.com wrote: given an array containing +ve n -ve numbers , can someone give efficient algo to find the max cont subarray product. this is same as problem http://online-judge.uva.es/p/v110/11059.html. here is the code for this one: #include cstdio #include iostream #include algorithm #include limits.h using namespace std; /* Algorithm: 1. if there is no zero in the array, the number of negative number is even, max product would be product of all numbers. 2. so we partition array around zero points and calculate each subarray max product and max product would be the subarray which has max value among this. 3. if in the subarray, the number of negative number is odd, then we need to leave out -ve number either on left or right depending on which has lesser absolute value. */ long long int submaxproduct(int *a, int start, int end); long long int maxprod(int *a, int n) { long long int maxprod = INT_MIN; long long int maxarrprod = 0; int start=0,i; if ( a == NULL || n == 0 ) return 0; for ( i = 0; i n; i++ ) { if ( a[i] == 0 ) { if ( i != 0 a[i-1] != 0 ) { maxarrprod = submaxproduct(a, start, i-1); if ( maxarrprod maxprod ) maxprod = maxarrprod; } start = i+1; } else if ( i == n-1 ) { maxarrprod = submaxproduct(a, start, i); if ( maxarrprod maxprod ) maxprod = maxarrprod; } } if ( maxprod 0 ) maxprod = 0; return maxprod; } long long int submaxproduct(int *a, int start, int end) { int lprod=1,rprod=1; int lneg=0,rneg=0; long long int mprod=1; int count=0; int i; for ( i = start; i=end;i++ ) { mprod *= a[i]; if ( a[i] 0 lneg == 0 ) lprod *= a[i]; else if ( a[i]0 rneg != 0 ) rprod *= a[i]; else if ( a[i] 0 lneg != 0 ) { count++; rneg = a[i]; rprod = 1; } else if ( a[i] 0 ) { count++; lneg = rneg = a[i]; } } if ( ( count 0 (end-start) == 0) || count%2 == 0 ) return mprod; else { long long int maxf = max(rneg*rprod,lneg*lprod); return mprod/maxf; } } int main() { int n; int count = 1; int i; while ( cinn ) { int a[n]; for ( i = 0; i n; i++ ) { cin a[i]; } printf(Case #%d: The maximum product is %lld.,count++,maxprod(a,n)); printf(\n\n); } return 0; } thayumanavar s -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] probabilty
he speaks the truth 1/4 time...the probability of 6 is 1/6so isnt it just 1/4*1/6=1/24?? On Fri, Aug 5, 2011 at 12:54 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: yes it cant be 1/8 I was wrong. On Fri, Aug 5, 2011 at 4:23 PM, coder dumca coder.du...@gmail.com wrote: i think it should be 3/4 On Fri, Aug 5, 2011 at 4:20 PM, aditi garg aditi.garg.6...@gmail.comwrote: 1/8 On Fri, Aug 5, 2011 at 4:14 PM, coder dumca coder.du...@gmail.comwrote: A man speaks truth 3 out of 4 times. He throws a die and reports it to be a 6. What is the probability of it being a 6? 1 /2 3 /4 5 /8 1 /8 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] probabilty
oops sorry there On Fri, Aug 5, 2011 at 1:13 PM, aditi garg aditi.garg.6...@gmail.comwrote: @arun he speaks truth 3/4 times On Fri, Aug 5, 2011 at 4:40 PM, Arun Vishwanathan aaron.nar...@gmail.comwrote: he speaks the truth 1/4 time...the probability of 6 is 1/6so isnt it just 1/4*1/6=1/24?? On Fri, Aug 5, 2011 at 12:54 PM, Nitin Nizhawan nitin.nizha...@gmail.com wrote: yes it cant be 1/8 I was wrong. On Fri, Aug 5, 2011 at 4:23 PM, coder dumca coder.du...@gmail.comwrote: i think it should be 3/4 On Fri, Aug 5, 2011 at 4:20 PM, aditi garg aditi.garg.6...@gmail.comwrote: 1/8 On Fri, Aug 5, 2011 at 4:14 PM, coder dumca coder.du...@gmail.comwrote: A man speaks truth 3 out of 4 times. He throws a die and reports it to be a 6. What is the probability of it being a 6? 1 /2 3 /4 5 /8 1 /8 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] probabilty
@nitin: oh yes i dint see that coming...good working On Fri, Aug 5, 2011 at 1:49 PM, Arun Vishwanathan aaron.nar...@gmail.comwrote: oops sorry there On Fri, Aug 5, 2011 at 1:13 PM, aditi garg aditi.garg.6...@gmail.comwrote: @arun he speaks truth 3/4 times On Fri, Aug 5, 2011 at 4:40 PM, Arun Vishwanathan aaron.nar...@gmail.com wrote: he speaks the truth 1/4 time...the probability of 6 is 1/6so isnt it just 1/4*1/6=1/24?? On Fri, Aug 5, 2011 at 12:54 PM, Nitin Nizhawan nitin.nizha...@gmail.com wrote: yes it cant be 1/8 I was wrong. On Fri, Aug 5, 2011 at 4:23 PM, coder dumca coder.du...@gmail.comwrote: i think it should be 3/4 On Fri, Aug 5, 2011 at 4:20 PM, aditi garg aditi.garg.6...@gmail.comwrote: 1/8 On Fri, Aug 5, 2011 at 4:14 PM, coder dumca coder.du...@gmail.comwrote: A man speaks truth 3 out of 4 times. He throws a die and reports it to be a 6. What is the probability of it being a 6? 1 /2 3 /4 5 /8 1 /8 -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon Question
hmm the problem is we need O(1) spacehaving that count wont make it O(1). i had an approach in mind of O(n) time and O(1) space..problem is i havent tested/debugged the code but it is O(1) space i guess and O(n) time. if total number of zeros(M) and 1s(N) are same print the whole array else the logic i used is something like this... 1)traverse the array from 0 to n 2)2 pointers , one pointing to the first 0 and other pointing to the first 1 in the array 3)i and j are 2 variables to keep count of 0 and 1 that we have seen so far as we keep traversing 4) 2 more varibales are used to maintain count of left over 0s and 1s from our current position( we know the total number of zeros and ones in O(n)) 5)if at any point i is equal to j and either left over 0s or 1s is 0 then print array from lesser of pointer index(lesser means one of the pointers is behind the other) till current index we are looking at the prtining from lesser pointer index till current index is if only none of the pointers have been changed in the process in between 6) in case i or j becomes greater than N or M repsectively i do some steps with pointer updation...i am just posting the codemaybe u can check and see if it is logically ok..it hasnt been tested M is number of zerso in array N is number of ones in array ptri=pointer to array ptrj=pointer to array i and j hold count of 0 and 1 respectively as i move along array M is number of zeros N is number of ones in the array ..u can find this in O(n)..if they are equal print whole array else chnagei=0; changej=0; ptri=null ptrj=null; done0=0; done1=0; savestart=null saveend=Null; for(int index=0;indexn;index++) { if(a[index]==0 done0 ==0) { ptri=a+index; done0++; } if(a[index]==1 done1 ==0) { ptrj=a+index; done1++; } if(a[index]==0) i++; if(a[index]==1) j++; lefti=M-i; //number of 0s left in array leftj=N-j; //number of 1 left in array if((lefti==0 || leftj==0 )(i==j)) { if(changei==0 chnagej==0) { if(ptriptrj) { savestart=ptri; saveend=a+index; break; } else { savestart=ptrj; saveend=a+index; break; } } else { if(i==j) { if(ptriptrj) { savestart=ptrj; saveend=a+index; } else { savestart=ptri; saveend=a+index; }//end of if } }//end of else } lefti=M-i; leftj=N-j; if(iN) { ptri=ptri+(N-i) changei=1; i=i-(N-i); if(j!=0 iN-j) { j=0; N--; } } if(jM) { ptrj=ptrj+(M-j); changej=1; j=j-(M-j); if(i!=0 jM-i) { i=0; M--; } } } print from save start to save end..that is answer On Fri, Aug 5, 2011 at 1:09 PM, surender sanke surend...@gmail.com wrote: Hi, for 1 do +1 for 0 do -1 maintain count at every index of array eg: 100110 array X 1 0 0 0 0 0 0 1 1 0 count 0 1 0 -1 -2 -3 -4 -5 -4 -3 -4 index -1 0 1 2 3 4 5 6 7 8 9 find count with same value having max index difference. -3 is count at index 4 and 8 max difference is 8-4 = 4 -4 is count at index 5 and 9 max difference is 9-5 = 4 to reduce traverse time after count calculation take a mapcount,i,j; i - first index of array having same count, j - last index of array having same count as and when u encounter count create map value with i else if already exist update j, and update max with MAX(j-i,max) Surender On Fri, Aug 5, 2011 at 2:25 PM, Arun Vishwanathan aaron.nar...@gmail.com wrote: by the way doesnt it look like an O(n^2) algo? On Fri, Aug 5, 2011 at 10:53 AM, Arun Vishwanathan aaron.nar...@gmail.com wrote: would u mind giving a short explanation of yr code too if possible? On Thu, Aug 4, 2011 at 5:38 PM, Apoorve Mohan apoorvemo...@gmail.comwrote: I think this should worktell me if this works... void longest_0_1_substring(char *str) { int size=0,count=0,max=0,pos=0,prev=0,prev_pos=0,ptr=0,i=0,j=0; while(*str++) size++; str -= (size + 1); while(isize) { for(j=i;(j size) (str[j]==str[j+1]);++j) count++; count++; if(ptr 1) { if(count = prev) { if(prev max) { max = prev; pos = prev_pos; } } else { if(count max) { max = count; pos = i - prev; } } } prev = count; prev_pos = i; i += count; ++ptr; count = 0; } printf(substring starts at position %d and is of size %d .,pos,max); } On Thu, Aug 4, 2011 at 6:25 PM, himanshu
Re: [algogeeks] Re: Puzzle
I guess anubhav soln seems ok On Thu, Aug 4, 2011 at 8:50 PM, ankit sambyal ankitsamb...@gmail.comwrote: @aditi:Thats a non uniform rope. The 1st half may burn faster than 2nd half. btw Priyanka's solution is correct. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] simple doubt
I guess someone had posted a link earlier from which I have a basic doubt when u have int arr[3]={1,0,2}; int **dp; int (*pa)[3]; is this the right assingment for instance? pa=arr; dp=arr; or have I flipped the ampersand in assigning? Also when I do pa++ will it jump by size of int or the whole array size it points to? -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] simple doubt
i see but is not arr a pointer to first array element and so arr contain address of that pointer ? On Fri, Aug 5, 2011 at 4:06 PM, Vijay Khandar vijaykhand...@gmail.comwrote: I dont think so dp=arr; since **dp; dp contains the addr of another ptr variable... On Fri, Aug 5, 2011 at 7:27 PM, Arun Vishwanathan aaron.nar...@gmail.com wrote: I guess someone had posted a link earlier from which I have a basic doubt when u have int arr[3]={1,0,2}; int **dp; int (*pa)[3]; is this the right assingment for instance? pa=arr; dp=arr; or have I flipped the ampersand in assigning? Also when I do pa++ will it jump by size of int or the whole array size it points to? -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] simple doubt
@nishant : where is the array address getting changed in first one? it just says pa=arr isnt arr address of the pointer to the first element of the array? On Fri, Aug 5, 2011 at 6:21 PM, nishaanth nishaant...@gmail.com wrote: i think both are erroneous. first statement i think you are trying to change the array address which is not possible. second statementarr doesn't make any sense i guess arr gives the address but arr is not allowed On Fri, Aug 5, 2011 at 4:19 PM, Vijay Khandar vijaykhand...@gmail.comwrote: but u initialized **dp means . ex-dp=p and p=arr then its correct so dp contains addr of p which inturns contains addrof arr now **dp is correct initialization. On Fri, Aug 5, 2011 at 7:45 PM, Arun Vishwanathan aaron.nar...@gmail.com wrote: i see but is not arr a pointer to first array element and so arr contain address of that pointer ? On Fri, Aug 5, 2011 at 4:06 PM, Vijay Khandar vijaykhand...@gmail.comwrote: I dont think so dp=arr; since **dp; dp contains the addr of another ptr variable... On Fri, Aug 5, 2011 at 7:27 PM, Arun Vishwanathan aaron.nar...@gmail.com wrote: I guess someone had posted a link earlier from which I have a basic doubt when u have int arr[3]={1,0,2}; int **dp; int (*pa)[3]; is this the right assingment for instance? pa=arr; dp=arr; or have I flipped the ampersand in assigning? Also when I do pa++ will it jump by size of int or the whole array size it points to? -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] simple doubt
@amol: hmm but I would like to know the reason for it if it is so On Fri, Aug 5, 2011 at 7:50 PM, Amol Sharma amolsharm...@gmail.com wrote: both are wrong.run and see that warning will be displayed !! -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Fri, Aug 5, 2011 at 10:17 PM, pankaj kumar pancsen...@gmail.comwrote: first one is right and second is wrong.because dp will store address of pointer and here you are storing address of int array. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily. -- 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 more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.