[algogeeks] Re: SPOJ Problem DP

2011-07-03 Thread shady
any spojjer in the group ? if you want i can post my solution with djikstra's :P ? Shady On Sat, Jul 2, 2011 at 10:31 AM, shady sinv...@gmail.com wrote: Hi, I am solving this http://www.spoj.pl/problems/DP/ problem using Djikstra's algorithm. What is the dynamic programming solution to this

[algogeeks] [Brain Teaser]Popular Puzzle of the week

2011-07-03 Thread Birender rawat
*Hi,* * * *Based on most comments, The popular puzzle of the last week is* * * * * * http://dailybrainteaser.blogspot.com/2011/06/find-next-number.html?biren=biren * * * ** * * *http://dailybrainteaser.blogspot.com/2011/06/equation-puzzle.html?** biren=biren* * * * * *You Can Also follow us on

Re: [algogeeks] Re: Interview Question

2011-07-03 Thread Sandeep Jain
I was thinking the same, BUT here the question is that we have two *SETS* and that's the catch. So, XORing all elements of SET A with SET B should result in ZERO only when both the set have same elements. Regards, Sandeep Jain On Sun, Jul 3, 2011 at 11:25 AM, Pranav Agarwal

Re: [algogeeks] [Brain Teaser]Popular Puzzle of the week

2011-07-03 Thread shady
banned :) On Sun, Jul 3, 2011 at 12:31 PM, Birender rawat birender.ra...@gmail.comwrote: *Hi,* * * *Based on most comments, The popular puzzle of the last week is* * * * * * http://dailybrainteaser.blogspot.com/2011/06/find-next-number.html?biren=biren * * * ** * *

Re: [algogeeks] Re: Interview Question

2011-07-03 Thread sunny agrawal
@sandeep SET A - {0,3,4,7} SET B - {1,2,5,6} xor of all elements is zero sum of both the sets is same no of elements in both are same overall result : all Algorithm posted above Fails On Sun, Jul 3, 2011 at 12:59 PM, Sandeep Jain sandeep6...@gmail.com wrote: I was thinking the same, BUT here

[algogeeks] Optimisation to reduce time...

2011-07-03 Thread rajeevrvis
Hi Here is the code . I want to optimize it to run faster . Can Anyone help me??? #includestdio.h void main() { int n,q,a[10]={0},b[10],c[10],d[10],i,count,j; scanf(%d%d,n,q); for(i=0;iq;i++) scanf(%d%d%d,b[i],c[i],d[i]); for(i=0;iq;i++) if(b[i]==0) {

Re: [algogeeks] Re: Interview Question

2011-07-03 Thread Sandeep Jain
Agreed, BUT if you don't add a stipulation. You won't be able to reduce the complexity. For a 100% general solution, I don't think you can reduce the complexity more than O(nLgn.) There are variations of this question: -- All numbers are non-zero and distinct. -- All numbers belong to given range

Re: [algogeeks] Optimisation to reduce time...

2011-07-03 Thread Sandeep Jain
Can you give an insight to what exactly this code does? That may help quiet a lot. Regards, Sandeep Jain On Sun, Jul 3, 2011 at 1:17 PM, rajeevrvis rajeev.open.1...@gmail.comwrote: Hi Here is the code . I want to optimize it to run faster . Can Anyone help me??? #includestdio.h void

Re: [algogeeks] Optimisation to reduce time...

2011-07-03 Thread sunny agrawal
You should have posted the problem link i think u are trying this one. http://www.codechef.com/problems/MULTQ3/ http://www.codechef.com/problems/MULTQ3/use RMQ or Binary Indexed Trees. Brute Force won't work On Sun, Jul 3, 2011 at 1:17 PM, rajeevrvis rajeev.open.1...@gmail.comwrote: Hi Here

Re: [algogeeks] Re: Interview Question

2011-07-03 Thread sunny agrawal
But i don't think xor method will work at all for all of the cases above you mentioned. setA = {4,7} setB = {5,6} - all numbers in both set are nonzero and distinct - all numbers are in some range :D and for character parts it will similarly failby taking character set of ascii values 4,5,6,7

[algogeeks] Re: Optimisation to reduce time...

2011-07-03 Thread rajeevrvis
@sunny Ok , Thanks On Jul 3, 12:58 pm, sunny agrawal sunny816.i...@gmail.com wrote: You should have posted the problem link i think u are trying this one. http://www.codechef.com/problems/MULTQ3/  http://www.codechef.com/problems/MULTQ3/use RMQ or Binary Indexed Trees. Brute Force won't work

Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread udit sharma
Its Ceiling of (n/2) In both cases atmost comparisons will be 3 * Ceiling of (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

Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread Nitish Garg
Which chapter of Sartaj Sahni are you referring to? -- 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/-/rWAgp3fzkrcJ. To post to this group, send email to

[algogeeks] VIRTUAL INHERITANCE

2011-07-03 Thread himanshu kansal
class Base { public: int a; }; class X: public Base { public: int x; }; class Y: public Base { public: int y; }; class Z:public X,public Y { }; int main() {coutsizeof(Base)endl; cout sizeof(X) endl; cout sizeof(Y) endl; cout sizeof(Z)

Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread sunny agrawal
refer CLRS topic 9.1 Maximum and Minimum page no 184 :) On Sun, Jul 3, 2011 at 2:32 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Which chapter of Sartaj Sahni are you referring to? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view

Re: [algogeeks] VIRTUAL INHERITANCE

2011-07-03 Thread abc abc
In the second case , the size of vptr will be added to each and every object . 1st class = one int :4 2nd class = one int +one int from base + vptr =12 3rd class = one int + one int from base + vptr =12 4th class =one int from each base class + one int from each of the grand parent +one vptr =20

[algogeeks] Re: VIRTUAL INHERITANCE

2011-07-03 Thread himanshu kansal
1 MORE QUESHOW IS DELEGATED TO SISTER CLASS IMPLEMENTED...MEANS HOW CAN ONE CLASS CALL ANOTHER CLASS'S FUNCTION WITHOUT KNOWING ANYTHING ABOUT IT On Sun, Jul 3, 2011 at 2:43 PM, himanshu kansal himanshukansal...@gmail.com wrote: class Base { public: int a; }; class

Re: [algogeeks] VIRTUAL INHERITANCE

2011-07-03 Thread himanshu kansal
shouldnt it be 16cz only one instance of base class gets included when we use virtual keyword.. On Sun, Jul 3, 2011 at 2:54 PM, abc abc may.i.answ...@gmail.com wrote: In the second case , the size of vptr will be added to each and every object . 1st class = one int :4 2nd class = one

Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread Nitish Garg
Thanks got it. On 7/3/11, sunny agrawal sunny816.i...@gmail.com wrote: refer CLRS topic 9.1 Maximum and Minimum page no 184 :) On Sun, Jul 3, 2011 at 2:32 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Which chapter of Sartaj Sahni are you referring to? -- You received this message

[algogeeks] Re: help..

2011-07-03 Thread cegprakash
@sameer: thank you On Jul 2, 3:47 pm, sameer.mut...@gmail.com sameer.mut...@gmail.com wrote: nn-1  is the expression to find out if n is a power of 2...If nn-1 returns 0 its a power of 2 else its not. And what sunny said is also ryt On Sat, Jul 2, 2011 at 3:47 PM, sunny agrawal

Re: [algogeeks] Re: Number of Comparisons!

2011-07-03 Thread vaibhav shukla
refer cormen.. chapter 9 ;) On Sun, Jul 3, 2011 at 3:19 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Thanks got it. On 7/3/11, sunny agrawal sunny816.i...@gmail.com wrote: refer CLRS topic 9.1 Maximum and Minimum page no 184 :) On Sun, Jul 3, 2011 at 2:32 PM, Nitish Garg

[algogeeks] Re: help..

2011-07-03 Thread cegprakash
@mohit: nice soln :) On Jul 2, 2:50 pm, mohit goel mohitgoel291...@gmail.com wrote: May be this can work.give any counter example... int count; main() {       int l,rope,cuts;       scanf(%d%d,l,rope);       count =0;        find_cuts(l,rope);        printf(cuts needed is %d,count);

[algogeeks] Re: help..

2011-07-03 Thread cegprakash
@mohit: a little change in your function to make it work..  int find_cuts(int l,int rope)  int find_cuts(int l,int rope) { if(l==rope) return count; count++; // printf(%d,count); l=l/2; if(l==rope) return count; if(ropel) rope =rope-l; return

[algogeeks] Re: help..

2011-07-03 Thread cegprakash
@avi dullu: explanation of your code plz.. On Jul 3, 3:57 am, Avi Dullu avi.du...@gmail.com wrote: Another alternative soln. int rec_cut(int l, int k) {   if (l == k) return 0;   int tmp = k - (l1);   return 1 + rec_cut(l1, tmp = 0 ? k : tmp); } int main() {   int l, k;   scanf(%d%d,

[algogeeks] Re: help..

2011-07-03 Thread cegprakash
i was actually trying this problem.. www.spoj.pl/problems/LQDCANDY I'm getting WA still.. #includemath.h #includestdio.h int cnt; inline int find_cuts(int l,int rope) { if(l==rope) return cnt; cnt++; l=l/2; if(l==rope) return cnt; if(ropel)

Re: [algogeeks] Re: help..

2011-07-03 Thread saurabh singh
I think its problem of overflow? the input data is 10^18.Otherwise the problem is trivial On Sun, Jul 3, 2011 at 7:02 PM, cegprakash cegprak...@gmail.com wrote: i was actually trying this problem.. www.spoj.pl/problems/LQDCANDY I'm getting WA still.. #includemath.h #includestdio.h

[algogeeks] Fwd: anu_test Segmentation fault

2011-07-03 Thread HARSH PAHUJA
-- Forwarded message -- From: HARSH PAHUJA hpahuja.mn...@gmail.com Date: Sun, Jul 3, 2011 at 8:37 AM Subject: anu_test Segmentation fault To: anutest...@googlegroups.com http://www.ideone.com/QuMcn plzz help. y the above program is giving seg fault #includestdio.h

Re: [algogeeks] Fwd: anu_test Segmentation fault

2011-07-03 Thread Vishal Thanki
Don't allocate too much static memory in stack, it will cause troubles. You are doing int[2000][2000], i.e. 2000*2000*4 bytes of memory in stack. Use dynamic memory allocation for such large chunk. I modified your code as below and it doesn't give seg fault. #includestdio.h #include malloc.h

Re: [algogeeks] Fwd: anu_test Segmentation fault

2011-07-03 Thread Shachin Sharma
You might want to try the following: limit This will show you the stacksize limit (I believe 1024 KB?) Execute the following command unlimit stacksize This should increase the stacksize and make the program work. The second thing is I agree with the fact the such huge static allocation

Re: [algogeeks] Re: Interview Question

2011-07-03 Thread Deoki Nandan
there is no possible solution for this question in less than O(nlgn) time. As by theorem given in cormen and solution is possible using xor On Sun, Jul 3, 2011 at 2:27 PM, Sandeep Jain sandeep6...@gmail.com wrote: For case1) yes XOR works, for Well, for the other two cases hash-maps may come

[algogeeks] Re: Interview Question

2011-07-03 Thread XYZ
Either you will have to use hashmaps which means extra storage or compromise on time complexity as nlogn I dont think there is any other possible workaround! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web

[algogeeks] find output

2011-07-03 Thread amit the cool
int main() { int a[]={5,10,15,8}; int *x=a; int y; y=*x++; printf(%d,y); } -- You received this 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

Re: [algogeeks] find output

2011-07-03 Thread Apoorve Mohan
5 On Mon, Jul 4, 2011 at 1:01 AM, amit the cool amitthecoo...@gmail.comwrote: int main() { int a[]={5,10,15,8}; int *x=a; int y; y=*x++; printf(%d,y); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] Re: Interview Question

2011-07-03 Thread Arpit Sood
Hey, what is the solution with XOR, methods mentioned above seem to fail there any reference ? On Sun, Jul 3, 2011 at 10:39 PM, Deoki Nandan deok...@gmail.com wrote: there is no possible solution for this question in less than O(nlgn) time. As by theorem given in cormen and

[algogeeks] array size problem

2011-07-03 Thread Deoki Nandan
WHY? In C++, you can do something like const int ArraySize = 100; int Array[ArraySize]; while in ANSI C, this would be flagged as an error. -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Re: array size problem

2011-07-03 Thread Gene
Why do bicycles have 2 wheels and tricycles 3? The designers made them that way. So you're probably asking why they were designed that way. C++ came after C. In general C++ seeks to de-emphasize use of the pre- processor because macro substitution is generally considered to make maintenance

[algogeeks] Re: VIRTUAL INHERITANCE

2011-07-03 Thread T3rminal
@abc abc 4th class= two ints from X and Y classes + one int from base class( as this class is shared ) + 2 virtual pointers of X and Y classes. On Jul 3, 2:24 pm, abc abc may.i.answ...@gmail.com wrote: In the second case , the size of vptr will be added to each and every object . 1st class =

Re: [algogeeks] Re: array size problem

2011-07-03 Thread Navneet Gupta
If you can, refer to Constants chapter in Bruce Eckel. He he smartly explained how const are different for C C++. The e-book is free to download from net. On Mon, Jul 4, 2011 at 2:50 AM, Gene gene.ress...@gmail.com wrote: Why do bicycles have 2 wheels and tricycles 3?  The designers made them

Re: [algogeeks] Delete a node in a BST!!

2011-07-03 Thread Navneet Gupta
It is a simple algorithm 1) If node has no child, simply delete 2) If node has one child, replace node's data with child's data and make the subtree child of node, delete child. 3) if node has two child, find the node with min key in right subtree (or max in left subtree), call it x, replace

Re: [algogeeks] find output

2011-07-03 Thread Sandeep Jain
Apoorve, please explain the reason for this output as well Regards, Sandeep Jain On Mon, Jul 4, 2011 at 1:06 AM, Apoorve Mohan apoorvemo...@gmail.comwrote: 5 On Mon, Jul 4, 2011 at 1:01 AM, amit the cool amitthecoo...@gmail.comwrote: int main() { int a[]={5,10,15,8};

Re: [algogeeks] find output

2011-07-03 Thread amit kumar
i think d answer sud be 10. but it comes out to be 5. xplain plz On Mon, Jul 4, 2011 at 10:30 AM, Sandeep Jain sandeep6...@gmail.com wrote: Apoorve, please explain the reason for this output as well Regards, Sandeep Jain On Mon, Jul 4, 2011 at 1:06 AM, Apoorve Mohan

Re: [algogeeks] Reverse

2011-07-03 Thread sagar pareek
OK On Thu, Jun 30, 2011 at 3:14 PM, Anders Ma xuejiao...@gmail.com wrote: On Tue, Jun 28, 2011 at 3:04 PM, sagar pareek sagarpar...@gmail.com wrote: I have 1 more solution :- #includestdio.h #includestring.h main() { int i,j,l; char arr[100]; printf(Enter the string\n);

Re: [algogeeks] linked list

2011-07-03 Thread sagar pareek
@Anantha Krishnan Well be specific just read the question again. it has only to reorder numbers... what problem will occur if it has more than one data fields we can traverse with help of digits and then swap all the data fields On Thu, Jun 30, 2011 at 5:03 PM, Anantha Krishnan

Re: [algogeeks] find output

2011-07-03 Thread Anantha Krishnan
y=*x++; this line executes like this: y=*x; x=x+1; // post increment Regards Anantha Krishnan On Mon, Jul 4, 2011 at 10:36 AM, amit kumar amitthecoo...@gmail.com wrote: i think d answer sud be 10. but it comes out to be 5. xplain plz On Mon, Jul 4, 2011 at 10:30 AM, Sandeep Jain

Re: [algogeeks] find output

2011-07-03 Thread Navneet Gupta
I think one rule of thumb for reading pre and post increment operators is 1) For Pre - Increment the value and use it (++x) 2) For Post - Use the value and increment it (x++) Similar is for pre and post decrement. I am not very good at commenting the generality of above but in simple usages