Re: [algogeeks] expectation values..
Can you provide the link?? On Sun, Jun 17, 2012 at 5:08 PM, Gaurav Popli gpgaurav.n...@gmail.comwrote: got it ..thanks!! and this was not asked in any interview as i know...i read this quesn from SPOJ.. On Sun, Jun 17, 2012 at 12:13 AM, Amitesh Singh singh.amit...@gmail.comwrote: just curious to know if this question is asked in any interviews? Google interview? -- Amitesh On Sun, Jun 17, 2012 at 12:09 AM, Amitesh Singh singh.amit...@gmail.comwrote: This problem is similar to Coupan collector problem. http://en.wikipedia.org/wiki/Coupon_collector%27s_problem In your case the answer is [image: For N-Dice ; \newline \sum_{i=1}^{N} N/i \newline for\; N =~2 ; \newline \sum_{i=1}^{2} 2/i = 2/1 + 2/2 = 3 \newline] Hope it helps! -- Amitesh On Sat, Jun 16, 2012 at 5:18 PM, Gaurav Popli gpgaurav.n...@gmail.comwrote: What is the expected number of throws of his die while it has N sides so that each number is rolled at least once? e.g for n=2 ans 3.00 n=12 ans is 37.24... i refrd to expectation tutuorial at http://www.codechef.com/wiki/tutorial-expectation but still couldnt get the logic... any help? -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Microsoft Interview Question
@Ashish @Saurabh , Recheck your solutions , order won't be maintained in your solutions. Its output will be = {-1 -6 -8 3 4 5 9 } On Thu, Jun 14, 2012 at 2:08 AM, Saurabh Yadav saurabh...@gmail.com wrote: @shiv relate the ashish solution with quick sort then you will understand easily On Thu, Jun 14, 2012 at 2:06 AM, Saurabh Yadav saurabh...@gmail.comwrote: +1 Ashish solution -- Thanks Regards Saurabh Yadav -- Thanks Regards Saurabh Yadav -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: problem
A correction, it is *(2^p) - 1 *, and the answer (*2^(number of primes less than n)) - 1* .(It is simply taking any subset of the primes,leaving the one in which do not take any prime) On Sun, Jun 10, 2012 at 10:03 PM, Piyush Kapoor pkjee2...@gmail.com wrote: The problem simply asks you to calculate the number of ways to express a number( = *N!^N!*) as product of two co prime numbers. For a general *N* , it is simply equal to *2^(p-1)* , where *p * is the number of distinct prime factors of *N*. For *N!* , *p* will be number of primes less than *N* , and for *N!^N!* it is same as *N!* , So the answer is *2^((number of primes less than N) - 1)* . On Sun, Jun 10, 2012 at 9:53 PM, payel roy smithpa...@gmail.com wrote: Can you please simplify the algorithm? Solution is not clear from the posted submissions !!! On 10 June 2012 20:32, KK kunalkapadi...@gmail.com wrote: This problem is of ACM-ICPC kanpur online round 2012. you can find the solution here. On Sunday, 10 June 2012 16:37:33 UTC+5:30, payel roy wrote: Find the number of fractions a/b such that- 1. gcd(a, b) = 1 2. 0 a/b 1 3. a * b = (n!) ^ (n!) Where n! denotes the factorial of n and ^ denotes power, i.e. (2!) ^ (2!) = 4. On Sunday, 10 June 2012 16:37:33 UTC+5:30, payel roy wrote: Find the number of fractions a/b such that- 1. gcd(a, b) = 1 2. 0 a/b 1 3. a * b = (n!) ^ (n!) Where n! denotes the factorial of n and ^ denotes power, i.e. (2!) ^ (2!) = 4. -- 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/-/0tnSKnC7YRYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Piyush Kapoor, 2nd year,CSE IT-BHU -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Array problem
@atul anand : it will work,i can give u the code. On Mon, Mar 12, 2012 at 11:53 AM, sanjiv yadav sanjiv2009...@gmail.comwrote: u r right. On Mon, Mar 12, 2012 at 11:17 AM, atul anand atul.87fri...@gmail.comwrote: @sanjiv : wont work for this test case :- {1,5,3,6,2,7,8}; On Mon, Mar 12, 2012 at 10:54 AM, sanjiv yadav sanjiv2009...@gmail.comwrote: @atul anand- It will still work as follows--- (3,0) / \(5,0+3) (1,0) \(6,0+3+5) \(2,0+1)\(7,0+3+5+6) \(8,0+3+5+6+7) here, my logic is that if number is grater than its parent,then add the parent in the current sum,else keep it as such. check it and made correction in my logic if i m wrong. On Mon, Mar 12, 2012 at 10:33 AM, atul anand atul.87fri...@gmail.comwrote: @piyush : i dont think so BIT would work over here , we are not just reporting cumulative sum tilll index i. On Mon, Mar 12, 2012 at 12:58 AM, Piyush Kapoor pkjee2...@gmail.comwrote: This can be done very easily with the help of a Binary Indexed Tree,and it is very short to code as well.Simply process the numbers in order,and for each number output the cumulative frequency of the index of the number you are processing. -- You received this message because you are subscribed 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 Sanjiv Yadav MobNo.- 8050142693 Email Id- sanjiv2009...@gmail.com -- You received this message because you are subscribed 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 Sanjiv Yadav MobNo.- 8050142693 Email Id- sanjiv2009...@gmail.com -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Array problem
1)First map the array numbers into the position in which they would be, if they are sorted,for example {30,50,10,60,77,88} --- {2,3,1,4,5,6} 2)Now for each number ,find the cumulative frequency of index ( = the corresponding number in the map - 1). 3)Output the cumulative frequency and increase the frequency at the position (=the corresponding number in the map) by the number itself. Example {3,5,1,6,7,8} Map of which would be {2,3,1,4,5,6} Process the numbers now, 1)3 comes ,find the cumulative frequency at index 1 ( = 2-1) which is 0. so output 0 Increase the frequency at index 2 to the number 3. 2)5 comes,find the CF at index 2( = 3-1) which is equal to 3 .output 3. Increase the frequency at index 3 to the number 5. 3)1 comes,CF at index 0 (=1-1) = 0 so output 0.increase the F at position 1 by 1. Similarly for others. -- You received this message because you are subscribed 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] ORDERS
First note that the person standing at the last position can be easily found,because if it has to move by X,then after shifting its position will be N-X,which will be the position in the sorted array ,(Array becomes sorted after shifting of the last person),and the number at position N-X will be N-X.So the person at the last position is N-X.Try to perform the same after deleting this element from the array.This will reduce the problem to a query/update problem ,and you will need a data structure such as balanced BST (such as AVL),or segment tree or BIT,or even tree representation of lists. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] someone pls explain the o/p??
xy is a mixed expression involving two operands of different types,one of unsigned int and other signed int.Since implicit type conversion takes place in such cases,the signed int is converted to unsigned int ,which means that -2(signed) is converted to 4294967294 (unsigned) .,and then the comparison takes place. http://ideone.com/VAyV5 -- You received this message because you are subscribed 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 : GAMECOIN
Use Combinatorics. The Question is equivalent to --- To find the number of ways to place 'H' such that no two are adjacent to each other Now we have following possibilities :: 1)Using exactly 0 'H' 's :: == 1 2)Using exactly 1 'H's ::== NC1 3)Using exactly 2 'H's ::== For this case , the arrangement would be something like this:: (tt...tt) H (tt..tt) H (tt.tt) --X ---Y-- ---Z- Let the number of 'T' s on the left side be X,middle be Y,and right be Z, then X+Y+Z=N-2 ,also Y=1 for H to not to be adjacent so X+(Y-1) +Z=N-3 the number of solutions == (N-3)+(3-1) C (3-1) == (N-1)C2 4)Using exactly 3 'H's::== (N-2)C3 and so on.. Answer = = 1+NC1 + (N-1)C2 + (N-2)C3 + . (till N-r =r) which is same as fibonacci series. So the answer was the fibonacci number divided by (2^n) -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] choosing numbers
Suppose u choose ith element from the Kth set,then dp[K][Sum]=sum(from i=0 to number of elements in the Kth set) dp[K-1][Sum-(ith element of Kth set)] On Sun, Oct 23, 2011 at 3:31 PM, cegprakash cegprak...@gmail.com wrote: hi i recently came across this problem.. there are K sets each sets can contain n numbers from 0 to n we've to choose exactly one number from each set the sum of all the elements that we chose should be equal to P. we have to find how many such possibilities are there to choose so.. for example assume there are 3 sets containing 1,2,3 elements in them so the first set contains 0 and 1 second set contains 0,1 and 2 third set contains 0,1,2 and 3 assume P=2 in this case there are 5 possibilities (0,0,2), (0,1,1), (0,2,0), (1,0,1), (1,1,0) i'm struggling for a DP solution!! help me out -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: rise and fall of power
In which library do powl() and log10l() lie(they r not in cmath,i think) ,can anybody post a good reference to these..(I could not find much on googling) -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: rise and fall of power
Yes these are in cmath(or math.h) , /* 7.12.6.8 Double in C89 */ extern float __cdecl log10f (float); extern long double __cdecl log10l (long double); -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: question
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, Arpit Sood -- You received this message because you are subscribed 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Kth largest element
use max heap ,it will take n + k*logn On Thu, Sep 8, 2011 at 10:25 PM, Rohit jalan jalanha...@gmail.com wrote: How to find out Kth largest element in an array ? -- Thanks Regards : ROHIT JALAN -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] ACM
Go Go Go!!! On Fri, Sep 9, 2011 at 11:07 AM, Kunal Patil kp101...@gmail.com wrote: Cool.. If you can share/ask algorithm related programming questions.. :) In fact it is the main cause of this group. :) :) :) There are sufficient SPOJ problem discussions over here.. You can continue asking questions if you think, that particular problem needs special data handling techniques to make it pass all the large test cases... :) On Fri, Sep 9, 2011 at 11:00 AM, Manish Verma jalsa.n.sa...@gmail.comwrote: Hey, anyone preparing for acm-icpc what about discussing acm-icpc questions here what say @shady?? -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Need algorithm asap
I think it is simply printing the subsets.Let Y1 be a subset,then Y-Y1 will be Y2,which will give u all the partitions... On Fri, Sep 2, 2011 at 7:04 PM, kranthi raj kranthi...@gmail.com wrote: I have a list / array Y (with n elements in it), and write an algorithm which gives all valid bipartitions (Y1 ,Y2) of Y. -- Sincerely, Kranthi Raj A 2nd Mtech Dept Of Computer Science , Indian Institute of Technology, Madras #9884989577 -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: SPOJ ACODE
You can check your answers on my AC code:: import java.io.*; import java.util.*; public class Main { public static void main(String args[])throws Exception { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); StringBuffer out=new StringBuffer(); String s; while(!(s=in.readLine()).equals(0)) { int l=s.length(); int dp[]=new int[l];char ar[]; ar=s.toCharArray(); if(ar[l-1]!='0') dp[l-1]=1; for(int j=l-2;j=0;j--) { int a=ar[j]-'0',b=ar[j+1]-'0'; if(j==(l-2) (10*a+b)=26) { if(a!=0) dp[j]=1+dp[j+1]; } else if(j==(l-2) (10*a+b)26) dp[j]=dp[j+1]; else if(j!=(l-2) (10*a+b)=26) { if(a!=0) dp[j]=dp[j+1]+dp[j+2]; } else { dp[j]=dp[j+1]; } } out.append(dp[0]+\n); } System.out.println(out); } } -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: SPOJ ACODE
There is nothing much particular to java,, Here is the code(simply copy pasted from the above one) in C:: int main(){ char ar[100]; int dp[1000]; scanf(%s,ar); if(ar[l-1]!='0') dp[l-1]=1; for(int j=l-2;j=0;j--) { int a=ar[j]-'0',b=ar[j+1]-'0'; if(j==(l-2) (10*a+b)=26) { if(a!=0) dp[j]=1+dp[j+1]; } else if(j==(l-2) (10*a+b)26) dp[j]=dp[j+1]; else if(j!=(l-2) (10*a+b)=26) { if(a!=0) dp[j]=dp[j+1]+dp[j+2]; } else { dp[j]=dp[j+1]; } } printf(%d\n,dp[0]); return 0; } -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] An Interesting DP Question
Let ways[n][k][prev] denote the number of ways of selecting a sequence of size K, where n is the current index,k is the size,prev is the previous chosen element in the sequence. then ways[n][k][prev]=ways[n][k][prev]+ways[n-1][k][prev], if a[n]=a[prev] ways[n][k][prev]=ways[n][k][prev]+ways[n-1][k][prev]+ways[n-1][k-1][n] , else (Recursion + Memoization) Code: int ways[10][10][10]; int ar[]={ 1, 4, 6, 2, 5,1000}; int i,j,k,K=3,N=4; int rec(int n,int k,int prev){ if(k==0) return 1; if(n0) return 0; if(~ways[n][k][prev]) return ways[n][k][prev]; else{ int a,b=0; a=rec(n-1,k,prev); if(ar[n]ar[prev]) b=rec(n-1,k-1,n); return ways[n][k][prev]=a+b; } } int main(){ for(i=0;i10;i++) for(j=0;j10;j++) for(k=0;k10;k++) ways[i][j][k]=-1; printf(%d\n,rec(N,K,N+1)); return 0; } Now,this code can easily be converted to a DP solution -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Another DP Question on String Palindrom
First of all for all substrings ,compute a boolean matrix ispalin[n][n] which is true if a substring from i to j is a palindrome.This can be easily done in O(n^2). Next,let min[n][n] be the dp array,then min[i][j]=1 ,if ispalin[i][j]=1 min[i][j]=minimum(min[i][k]+min[k+1][j]) for all k=i and kj. else On Thu, Aug 25, 2011 at 6:18 PM, WgpShashank shashank7andr...@gmail.comwrote: Given a string, and split it into as few strings as possible such that each string is a palindrome.Example ABAABABA Greedy algorithm: ABAABA + B + A = 3 palindromes Correct answer: ABA + ABABA = 2 palindromes so one thing sure Greedy Wont Works here , so it sounds perfect DP problem ? 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/-/0JfJCwLmEuMJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: spoj coin tossing
@keyan karthi Can you explain a bit on how to use the markov chain to get the answer... On Wed, Aug 24, 2011 at 11:42 PM, him himanshuarora.1...@gmail.com wrote: 1st one H-2^1+1 HTHT-2^4+4 TTHTHTHTHTHHTHTHTHTTHTHTT(33) - 2^33+6(why)? do you see any connection? On Aug 24, 6:55 am, keyankarthi keyankarthi1...@gmail.com wrote: http://www.spoj.pl/problems/MAIN8_D/ i tried solving this problem any ideas...?? for second test case 'htht' the states i considered are 1 T - (1/2) * x+1 2 HH - (1/4) * x+2 3 HTT - (1/8) * x+3 4 HTHH - (1/16) * x+4 5 HTHT - (1/16)(final state) x is the expected no of coins. x= 1 + 2+3+4+5 gives 16x=15x+26 x=26. answer given is 20... can any one explain this, -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Strange Billboard of Judge Spoj
For Dance Floor: 1)Note that the order in which you tap tiles is unimportant. 2)Try all subsets(or combinations) of tapping tiles on the first row,then in the other rows we only need to tap when the tile directly above is not lit. 3)Base condition will be when you finish with the last row,then the check if the last row contains all lit ones.. On Tue, Aug 23, 2011 at 4:47 AM, Victor Manuel Grijalva Altamirano kavic1.mar...@gmail.com wrote: I am trying the problem http://www.spoj.pl/problems/CERC07B/ and http://www.spoj.pl/problems/DFLOOR/ but i don´t have idea how to solve, anyone can help me??? -- Victor Manuel Grijalva Altamirano Universidad Tecnologica de La Mixteca -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: microsoft paper that i wrote today..
because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] String Question
Here is my algo: 1)Replace all '0' with '1' and '1' with '-1'(.i.e, 1 0 1 --- -1 1 -1) 2)Now take an array to calculate the sum of all elements from 1 to that index, which can be calculated as sum[i]=sum[i-1]+ar[i],take 0th element as 0. 3)Now the problem becomes finding two indices (say i,j) for which, sum[i]=sum[j] and j-i is maximum (ji) (This is easy to see as,Let for substring [i,j] the number of 1s is equal to number of 0's ,then sum[i,j]=0 as per our algo, OR we can state that sum[i-1]=sum[j],now for longest substring the difference should be maximum) example:- 1 0 1 -- -1 1 -1 --- sum array :: 0 -1 0 -1 take i=1and j=2,sum[i-1]=sum[j]=-1,and substring::string[1,2]= 1 0 (Answer) 4)Now,the above step can be done quickly using hashing(using array indexes) in O(n).(If n10^6) On Sat, Aug 13, 2011 at 9:53 PM, Yasir yasir@gmail.com wrote: Me too didn't get Raghavan's algo... Pls explain.. It seems that above algo will find only longest sequence starting from index 0. Just a thought: Along with raghavan's algo, what if I keep and array_of_integers[string_length] and keep on storing the count in this array. Once string is traversed we have to find the max distance among two equal numbers in an array. (need to think on this problem as well) -- 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/-/gWwbzXZ_B1sJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Array question: Detect whether a circular chain with all elements can be formed
Maybe you are looking for this:http://www.codechef.com/problems/WORDS1 On Sat, Aug 13, 2011 at 10:25 PM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: i got error,my sol will not work for all cases On Sat, Aug 13, 2011 at 10:22 PM, Kamakshii Aggarwal kamakshi...@gmail.com wrote: see the following example: *a*kdhd*a* ,*b*hdgd*c*, *c*hdjd*b* On Sat, Aug 13, 2011 at 10:20 PM, Yasir yasir@gmail.com wrote: why following? if(first==last) return false; example: axxa, ayyb, bzza === ayybbzzaaxxa -- 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/-/iONquZUgbPkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, Kamakshi kamakshi...@gmail.com -- Regards, Kamakshi kamakshi...@gmail.com -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Adobe Interview Question
what does step refer to in this case??? Please explain the example... On Sat, Aug 13, 2011 at 10:47 PM, Decipher ankurseth...@gmail.com wrote: How did you know that ? -- 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/-/GMle2k9i73wJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Problems on Linked List
Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Problems on Linked List
@naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.comwrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- You received this message because you are subscribed 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] Problems on Linked List
thanks all On Thu, Aug 11, 2011 at 12:21 AM, siddharam suresh siddharam@gmail.comwrote: 1)similar to list palindrome problem(soln already there in net) 2)it has discussed 2 day before on same group. please search once Thank you, Siddharam On Thu, Aug 11, 2011 at 12:01 AM, Piyush Kapoor pkjee2...@gmail.comwrote: @naveen for the first one,how will u traverse the list backwards.. I didnt understand your second solution,since the head is not given so how can u go from a node to the node to be deleted.. I forgot that in the first one,we are not allowed to use extra memory. Also do please mention the time complexity of your solutions.. On Wed, Aug 10, 2011 at 11:54 PM, Naveen Kumar naveenkumarve...@gmail.com wrote: for first reverse one of the link list by changing the pointer and than traverse one from backward and compare it the the other. for second. keep copying data from the next node to the node to be delete and remove the tail. This will not work if node to be deleted is the last node. On Wed, Aug 10, 2011 at 11:44 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Q1)Two linked Lists are given,i.e,their head pointers are given,and the problem is to check if the second one is reverse of the first one.Give the most efficient algo for it. Q2)A linked list is given,and one of its nodes is given.The problem is to delete the given node from the linked list.(The head node is not given). (In both of the above cases,the linked lists are singly linked lists.) -- Regards, Piyush Kapoor, 2nd year,CSE IT-BHU -- You received this message because you are subscribed 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] hi
hello On Tue, Aug 9, 2011 at 9:47 PM, sagar pareek sagarpar...@gmail.com wrote: How are you? On Tue, Aug 9, 2011 at 8:53 PM, arvind kumar arvindk...@gmail.com wrote: hi On Tue, Aug 9, 2011 at 8:24 PM, prashant gautam prashantgautam@gmail.com wrote: hello -- You received this message because you are subscribed 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 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. -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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] A Nice Programming Challenge Question
First sort the array.Then for each element,say x ,do a binary search to find the element y for which (y-x)=K or y=(x+K),if the elements are not distinct then the number of pairs will be the upper_bound()-lower_bound() for y. Complexity:O(nlogn) On Sun, Aug 7, 2011 at 11:23 PM, Yasir yasir@gmail.com wrote: Guys, Let's try to find out an efficient solution for the following prob: Given N numbers , [N=10^5] we need to count the total pairs of numbers that have a difference of K. [K0 and K1e9] Input Format: 1st line contains N K. 2nd line contains N numbers of the set. All the N numbers are assured to be distinct. Output Format: One integer saying the no of pairs of numbers that have a diff K. PS: Note that n is very large, so try to come up with an efficient solution. :) Source: http://www.interviewstreet.com/recruit/challenges/dashboard/ -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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: output???
I think it is because the numbers like 0.7 do not have a exact binary representation,so they are not exactly represented in float,while the constant is internally implemented as double.,Read this:: http://www.topcoder.com/tc?module=Staticd1=tutorialsd2=integersReals -- *Regards,* *Piyush Kapoor,* *2nd year,CSE IT-BHU* -- You received this message because you are subscribed 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 output
It is not showing compiler error on Codeblocks on my machine. On Thu, Jul 28, 2011 at 2:26 PM, prabhat prabhat0...@gmail.com wrote: i think there will be warning due to inner structure is not declaring variable. Inner structure must be like: struct yy { char s; struct xx *p; }a; On Jul 27, 9:22 pm, Aman Goyal aman.goya...@gmail.com wrote: #include‹stdio.h› main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; } ouput: compiler error. Any logical reasons? -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] SPOJ
What will happen if r=di,c=dj in your safe function,I think that is causing the error... On Sat, Jul 23, 2011 at 8:29 PM, viswanath vellaiappan viswanath.vellaiap...@gmail.com wrote: I agree with Shady on asking for algo for the problem but lets not be hard on posting spoj question on spoj forum as these too involves algorithm (our interest). @KK : Can you tell us the judging status you are hitting? (Wrong answer, timeout??). ~Viswanath. On Sat, Jul 23, 2011 at 4:57 PM, shady sinv...@gmail.com wrote: there's something called spoj forum, try posting it there secondly, ask whether ur algo is right or wrong, not the code On Sat, Jul 23, 2011 at 4:51 PM, KK kunalkapadi...@gmail.com wrote: www.spoj.pl/problems/SHOP Its a pretty easy Q... But m not able to figure out any silly mistake in my prog.. plzz help #includeiostream #includevector #includemap #includequeue using namespace std; char a[26][26]; int si, sj, di, dj, rows, cols; void BFS(vector vectorint v, int si, int sj, int rows, int cols); int safe(vector vectorint v, int r, int c, int current, int rows, int cols); int main() { freopen(input.txt, r, stdin); freopen(output.txt, w, stdout); int si, sj; while(1) { cin cols rows; if(rows == 0 cols == 0) break; vectorint row(26, INT_MAX); vector vectorint final(26, row); for(int i=0; irows; i++) for(int j=0; jcols; j++) { cin a[i][j]; if(a[i][j] == 'S') { si = i; sj = j; } else if(a[i][j] == 'D') { di = i; dj = j; a[i][j] = '0'; } } BFS(final, si, sj, rows, cols); cout final[di][dj] endl; /* for(int i=0; irows; i++) { for(int j=0; jcols; j++) cout final[i][j] ; cout endl; } cout endl; */ } return 0; } void BFS(vector vectorint v, int si, int sj, int rows, int cols) { pairint, int p; queue pairint, int q; q.push(make_pair(si, sj)); v[si][sj] = 0; while(!q.empty()) { p = q.front(); q.pop(); int current = v[p.first][p.second]; if(safe(v, p.first+1, p.second, current, rows, cols)) q.push(make_pair(p.first+1, p.second)); if(safe(v, p.first-1, p.second, current, rows, cols)) q.push(make_pair(p.first-1, p.second)); if(safe(v, p.first, p.second+1, current, rows, cols)) q.push(make_pair(p.first, p.second+1)); if(safe(v, p.first, p.second-1, current, rows, cols)) q.push(make_pair(p.first, p.second-1)); } } int safe(vector vectorint v, int r, int c, int current, int rows, int cols) { if(r = 0 r rows c = 0 c cols a[r][c] != 'X') { if(v[r][c] current + a[r][c] - '0') { v[r][c] = current + a[r][c] - '0'; return 1; } } return 0; } -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Whats wrong?
the expression *root causes the structure to be printed,which prints,(root-data=),10,(root-left=)0,(root-right)=0 and then the last value is (root-data),other remaining values are ignored On Fri, Jul 15, 2011 at 12:16 AM, sagar pareek sagarpar...@gmail.comwrote: #includestdio.h #includestdlib.h struct node { int data; struct node *left; struct node *right; }*root=NULL; main() { root=(struct node *)malloc(sizeof(struct node)); root-data=10; root-left=NULL; root-right=NULL; printf(root-%x--root--%x--*root--%d--(root-data)=%x--(root-left)=%x--(root--right)=%x,root,root,*root,(root-data),(root-left),(root-right)); } In this,program,i try to print address of struct members but it print zero for (root-data) and (root-left).it also print same value for root and (root-right).so anyone one can explain me in detail how struct members stored in memory. -- **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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 doubt
Shouldn't the value of 1100 be -64 On Wed, Jul 13, 2011 at 4:53 PM, Anika Jain anika.jai...@gmail.com wrote: binary equivalent of 5.2 is 101.0011001100110011001100110011(nonterminating).. now it is actually stored in normalised frorm in 32 bits.. like this --1 bit for sign8 bits for exponent-23 bits for fraction-- this is from higher order byte to lower order for little endian.. if no. is positive sign bit is 0 else it is 1 The rule says change your floating point no. in such a form that after 1st digit that is 1 decimal point comes sooo here it becomes like 1.0100110011001100110011001100110011(nonterminating) * 2^2 so i here get an exponent of 2 as 2 here.. now in exponent 8 bits this exponent is stored as 127+exponent so here it becomes 1001.. now fraction here is clearly value after the decimal point i.e. 01001100110011001100110011001100110011(non terminationg) but only 1st 23 bits are saved rest are left so finally wht we get is: 1100 10100110 01100110 01100110 (64) (-90) (102)(102) On Wed, Jul 13, 2011 at 2:49 PM, Piyush Kapoor pkjee2...@gmail.comwrote: why do we need a NthIntWithKBits() in this topic? On Tue, Jul 12, 2011 at 7:58 AM, oppilas . jatka.oppimi...@gmail.comwrote: On Mon, Jul 11, 2011 at 5:54 PM, Piyush Kapoor pkjee2...@gmail.comwrote: Can anybody give a full explanation http://ideone.com/K1QmV On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.com wrote: try to find out the binary representation of float value 5.2 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.comwrote: int main(){ int i; float a=5.2; char *ptr; ptr=(char *)a; for(i=0;i=3;i++) printf(%d ,*ptr++); } output: 102 102 -90 64.explain? -- You received this message because you are subscribed 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 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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: Minimum/Maximum Sum path in A Binary Tree
I agree with anonymous procrastination On Wed, Jul 13, 2011 at 12:38 PM, anonymous procrastination opamp1...@gmail.com wrote: int maxsum(NODEPTR root) { if(root==NULL) return 0; else return MAX(maxsum(root-left),maxsum(root-right))+root-data; } This should work. Please comment. -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 doubt
why is the order of numbers reversed? On Wed, Jul 13, 2011 at 8:07 PM, Anika Jain anika.jai...@gmail.com wrote: sorry its 0100 not 1100 coz 5.2 is a positive no. so sign bit is 0 On Wed, Jul 13, 2011 at 7:58 PM, Piyush Kapoor pkjee2...@gmail.comwrote: Shouldn't the value of 1100 be -64 On Wed, Jul 13, 2011 at 4:53 PM, Anika Jain anika.jai...@gmail.comwrote: binary equivalent of 5.2 is 101.0011001100110011001100110011(nonterminating).. now it is actually stored in normalised frorm in 32 bits.. like this --1 bit for sign8 bits for exponent-23 bits for fraction-- this is from higher order byte to lower order for little endian.. if no. is positive sign bit is 0 else it is 1 The rule says change your floating point no. in such a form that after 1st digit that is 1 decimal point comes sooo here it becomes like 1.0100110011001100110011001100110011(nonterminating) * 2^2 so i here get an exponent of 2 as 2 here.. now in exponent 8 bits this exponent is stored as 127+exponent so here it becomes 1001.. now fraction here is clearly value after the decimal point i.e. 01001100110011001100110011001100110011(non terminationg) but only 1st 23 bits are saved rest are left so finally wht we get is: 1100 10100110 01100110 01100110 (64) (-90) (102)(102) On Wed, Jul 13, 2011 at 2:49 PM, Piyush Kapoor pkjee2...@gmail.comwrote: why do we need a NthIntWithKBits() in this topic? On Tue, Jul 12, 2011 at 7:58 AM, oppilas . jatka.oppimi...@gmail.comwrote: On Mon, Jul 11, 2011 at 5:54 PM, Piyush Kapoor pkjee2...@gmail.comwrote: Can anybody give a full explanation http://ideone.com/K1QmV On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.com wrote: try to find out the binary representation of float value 5.2 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.comwrote: int main(){ int i; float a=5.2; char *ptr; ptr=(char *)a; for(i=0;i=3;i++) printf(%d ,*ptr++); } output: 102 102 -90 64.explain? -- You received this message because you are subscribed 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 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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
Re: [algogeeks] c doubt
Will u guyz pls tell me frm where do u study terms like endian ,it is a pity i had to google it :( :( On Wed, Jul 13, 2011 at 10:30 PM, Anika Jain anika.jai...@gmail.com wrote: ya thts ryt, for big endian it will be 64 -90 102 102 On Wed, Jul 13, 2011 at 10:22 PM, sunny agrawal sunny816.i...@gmail.comwrote: I think it is machine dependent and current output is for a little endian machine and output should be reverse for a big endian machine On Wed, Jul 13, 2011 at 10:18 PM, Anika Jain anika.jai...@gmail.comwrote: it is not unsigned its signed but positive thts y it is 0.. the order isnt reversed.. look at the code, the code 1st prints lowest order byte then next and then next and then highest soo output is 102 102 -90 64 On Wed, Jul 13, 2011 at 8:08 PM, Piyush Kapoor pkjee2...@gmail.comwrote: why is the order of numbers reversed? On Wed, Jul 13, 2011 at 8:07 PM, Anika Jain anika.jai...@gmail.comwrote: sorry its 0100 not 1100 coz 5.2 is a positive no. so sign bit is 0 On Wed, Jul 13, 2011 at 7:58 PM, Piyush Kapoor pkjee2...@gmail.comwrote: Shouldn't the value of 1100 be -64 On Wed, Jul 13, 2011 at 4:53 PM, Anika Jain anika.jai...@gmail.comwrote: binary equivalent of 5.2 is 101.0011001100110011001100110011(nonterminating).. now it is actually stored in normalised frorm in 32 bits.. like this --1 bit for sign8 bits for exponent-23 bits for fraction-- this is from higher order byte to lower order for little endian.. if no. is positive sign bit is 0 else it is 1 The rule says change your floating point no. in such a form that after 1st digit that is 1 decimal point comes sooo here it becomes like 1.0100110011001100110011001100110011(nonterminating) * 2^2 so i here get an exponent of 2 as 2 here.. now in exponent 8 bits this exponent is stored as 127+exponent so here it becomes 1001.. now fraction here is clearly value after the decimal point i.e. 01001100110011001100110011001100110011(non terminationg) but only 1st 23 bits are saved rest are left so finally wht we get is: 1100 10100110 01100110 01100110 (64) (-90) (102)(102) On Wed, Jul 13, 2011 at 2:49 PM, Piyush Kapoor pkjee2...@gmail.comwrote: why do we need a NthIntWithKBits() in this topic? On Tue, Jul 12, 2011 at 7:58 AM, oppilas . jatka.oppimi...@gmail.com wrote: On Mon, Jul 11, 2011 at 5:54 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Can anybody give a full explanation http://ideone.com/K1QmV On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.com wrote: try to find out the binary representation of float value 5.2 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.com wrote: int main(){ int i; float a=5.2; char *ptr; ptr=(char *)a; for(i=0;i=3;i++) printf(%d ,*ptr++); } output: 102 102 -90 64.explain? -- You received this message because you are subscribed 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 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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
Re: [algogeeks] c doubt
thanks,i hv just entered 2nd year,so most probably i will study this year -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 code bst mirror prob
u need a pointer to a pointer to swap the pointers... On Thu, Jul 14, 2011 at 1:21 AM, Anika Jain anika.jai...@gmail.com wrote: can some body tell me that: void swap(node *p,node *q) { node *t; t=p; p=q; q=t; } void mirror(node *p) { if (p==NULL) return; else {mirror(p-r); mirror(p-l); swap(p-r,p-l); } } in this the swapping is occuring but if i do : void mirror(node *p) { if (p==NULL) return; else {mirror(p-r); mirror(p-l); node *t; t=p-r; p-r=p-l; p-l=t; } } here it is not getting done .. why?? -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 doubt
Can anybody give a full explanation On Sat, Jul 9, 2011 at 10:49 PM, sunny agrawal sunny816.i...@gmail.comwrote: try to find out the binary representation of float value 5.2 On Sat, Jul 9, 2011 at 10:46 PM, Sangeeta sangeeta15...@gmail.com wrote: int main(){ int i; float a=5.2; char *ptr; ptr=(char *)a; for(i=0;i=3;i++) printf(%d ,*ptr++); } output: 102 102 -90 64.explain? -- You received this message because you are subscribed 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 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Reversing the order of words in String
char a[20]; int l; int main() { char str[100]; scanf(%s,str); l=strlen(str); } -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Reversing the order of words in String
Pls Ignore my above post.. On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor pkjee2...@gmail.com wrote: char a[20]; int l; int main() { char str[100]; scanf(%s,str); l=strlen(str); } -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Reversing the order of words in String
char a[20]; int l,i,j,k; int main() { char str[100]; gets(str); l=strlen(str); for(i=l-1;i=0;){ k=19; a[k]='\0'; while(i=0 str[i]!=' '){ a[--k]=str[i--]; } printf(%s,a+k); while(i=0 str[i]==' ') i--; printf( ); } } On Thu, Jul 7, 2011 at 10:37 PM, Piyush Kapoor pkjee2...@gmail.com wrote: Pls Ignore my above post.. On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor pkjee2...@gmail.comwrote: char a[20]; int l; int main() { char str[100]; scanf(%s,str); l=strlen(str); } -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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: Some adobe interview questions.
7 occurs 1 time... so 8th digit is 1 On Wed, Jul 6, 2011 at 1:02 AM, aditya kumar aditya.kumar130...@gmail.comwrote: in 7000 : '0' occurs seven times and rst of the numbers occur zero times. i still dint get where i am wrong . plz explain me . On Wed, Jul 6, 2011 at 12:47 AM, L prnk.bhatna...@gmail.com wrote: @aditya : I am wondering how many times 7 has occurred. Is it 1? Or is it 0? Please take a moment before posting your solution, and think whether it is write or wrong! On Jul 6, 12:11 am, aditya kumar aditya.kumar130...@gmail.com wrote: Q3. ans:7000 i guess this is also a correct answer and no unique soln as such On Wed, Jul 6, 2011 at 12:37 AM, aditya kumar aditya.kumar130...@gmail.comwrote: boolean palindromeCheck(String string) { len=string.length(); if((string.length()1)) { if((string.charAt(0)==string.charAt(len-1))) { str=; str=str+string.substring(1,(len-1)); palindromeCheck(str); } else { flag=false; } } return flag; } THis also works fine if you dont want to use pointer On Tue, Jul 5, 2011 at 9:37 PM, Azhar Hussain azhar...@gmail.com wrote: For Q4: I think this is the optimal code int recurPalin(char *start, char *end) { if (end start) return true; if (*start != *end) return false; return recurPalin(start+1, end-1); } - Azhar. On Tue, Jul 5, 2011 at 12:21 PM, vikas mehta...@gmail.com wrote: My program for Q4. // recursively find if a given string is palindrome bool IsPalindrome(string s, int start, int start2, bool flag) { bool flag1 = flag; if (start = 0 start2 (s.Length)) { char c1 = s[start]; char c2 = s[start2]; if (c1.Equals(c2)) { if (start == 0 start2 == s.Length - 1) { flag = true; } if (IsPalindrome(s, start - 1, start2 + 1, flag)) { flag1 = true; } } } return flag1; } while calling if (s.Length % 2 != 0) { p.IsPalindrome(s, s.Length / 2 - 1, s.Length / 2 + 1, false); } else { p.IsPalindrome(s, s.Length / 2 - 1, s.Length / 2, false); } -- 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/-/I6SVTB0o-uUJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Taking Input
you can use gets() ,to read a line and then easily find the individual numbers On Sun, Jul 3, 2011 at 1:22 AM, anonymous procrastination opamp1...@gmail.com wrote: Hello, I came across a problem where the first line of the input specfies a number n. Then next n lines, every line contains a few(no limit) number seperated by spaces. Then I want to find the sm of numbers on each line. eg. INPUT 5 1 4 5 3 1 6 11 23 1 9 8 7 6 7 7 7 Now algorithm offcourse is not a problem. But I'm not getting how to take input in C. This is driving me crazy. tried with scanf and getchar but unable to get it right. Please help -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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: HOW TO IMPLEMENT WITH DP..
This is an easy DP question,and as a hint,try considering the number of employees in a month as a state... On Fri, Jul 1, 2011 at 10:55 PM, Ritesh Srivastava riteshkumar...@gmail.com wrote: You can find many sites which classify SPOJ problems. The one I know is http://vnoi.info/index.php?option=com_vojtask=classifysite=spoj By the way , that one is a very simple DP problem. On Jul 1, 9:49 pm, prathimzn prathi...@gmail.com wrote: can anyone tell me hoe to think with DP in this ques. *- - - - - WITH REGARDS, * * PRAMENDRA RATHI * ** *B.TECH 2ND YEAR* *COMPUTER SCIENCE AND ENGINEERING* *NIT ALLAHABAD* On Fri, Jul 1, 2011 at 3:32 PM, prathimzn prathi...@gmail.com wrote: here is a question: https://www.spoj.pl/problems/MKBUDGET/ can anyone tell me how to implement this by DP.. i could implement it.. and how you will grade this ques ; is this a simple DP ques or good ONE..? *- - - - - WITH REGARDS, * *PRAMENDRA RATHI * ** *B.TECH 2ND YEAR* *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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] BST
Order Statistics Tree On Wed, Jun 29, 2011 at 8:15 PM, sunny agrawal sunny816.i...@gmail.comwrote: At each node if we store the Number of nodes in the left subtree.we can find kth smallest in O(lgn) else do a inorder traversal for k nodes On Wed, Jun 29, 2011 at 8:07 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: how to find kth smallest element in BST... -- You received this message because you are subscribed 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 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Coing tossing(SPOJ)
Can somebody give a link to a good tutorial on expected values,which can be used to solve this kind of problems, (One of the links from which I have already read is http://www.codechef.com/wiki/tutorial-expectation,though it did not help much) On Tue, Jun 28, 2011 at 7:06 PM, anubhav gupta anubhav.7...@gmail.comwrote: http://www.se.cuhk.edu.hk/~seem3570/12-pattern.pdf On Tue, Jun 28, 2011 at 5:26 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Hey The question I am currently working on is http://www.spoj.pl/problems/MAIN8_D/ Actually I am unable to understand how the answer for HTHT is 20. I know that the worst case for a string of 4 coin tosses should be 16*4. But how the expected value is 20? Can anyone explain? Thanks -- 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/-/DFckKu4bb-0J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Algorithms
The page is too long to read :P :P On Tue, Jun 28, 2011 at 9:45 PM, Navneet Gupta navneetn...@gmail.comwrote: http://en.wikipedia.org/wiki/List_of_algorithms How many do you know? :) --Navneet -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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: Cisco Question
Yep,I also want to know the same.. On Mon, Jun 27, 2011 at 6:23 PM, rajeev bharshetty rajeevr...@gmail.comwrote: @ Dave How to think about the answer to the above question . I mean How do I tackle such problems ? On Mon, Jun 27, 2011 at 6:17 PM, Dave dave_and_da...@juno.com wrote: y = ((x 0x55) 1) | ((x 1) 0x55). Note, 0x55 = 01010101 in binary. Dave On Jun 27, 7:18 am, rShetty rajeevr...@gmail.com wrote: Given a byte, write a code to swap every two bits. [Using bit operators] Eg: Input: 10 01 11 01 Output: 01 10 11 10 -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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: Cisco Question
thanks a lot for the wonderful explanation :-) On Mon, Jun 27, 2011 at 7:17 PM, Dave dave_and_da...@juno.com wrote: @Rajeev and Piyush: Numbering the bits from the right starting with 0 as usual, you see that you need to move the even-numbered bits one bit to the left and the odd-numbered bits one bit to the right. You could do this one bit-pair at a time, but it would be more efficient if you could do all pairs simultaneously. So how can you pick out all of the even-numbered bits at the same time? By using the logical and of the data with a mask that has 0s in the odd bit positions and 1s in the even bit positions. I.e., anding x with 01010101 in binary, which is 0x55 in hexadecimal. Once you have isolated the even numbered bits, you shift them left one place. The result is (x 0x55) 1. Similarly, you want to isolate the odd-numbered bits and shift them right one place. You could do that by anding with the mask 10101010 (binary) = 0xAA, and then shifting right: (x 0xAA) 1. This introduces another constant, which might not be as efficient as reusing the previous constant 0x55, which can be done by shifting right first and then anding: (x 1) 0x55. Now that we have the two sets of bits in the correct positions, we simply need to combine them, and the logical or operator does that just fine. The overall result is (x 0x55) 1) | ((x 1) 0x55). Dave On Jun 27, 7:53 am, piyush kapoor pkjee2...@gmail.com wrote: Yep,I also want to know the same.. On Mon, Jun 27, 2011 at 6:23 PM, rajeev bharshetty rajeevr...@gmail.com wrote: @ Dave How to think about the answer to the above question . I mean How do I tackle such problems ? On Mon, Jun 27, 2011 at 6:17 PM, Dave dave_and_da...@juno.com wrote: y = ((x 0x55) 1) | ((x 1) 0x55). Note, 0x55 = 01010101 in binary. Dave On Jun 27, 7:18 am, rShetty rajeevr...@gmail.com wrote: Given a byte, write a code to swap every two bits. [Using bit operators] Eg: Input: 10 01 11 01 Output: 01 10 11 10 -- You received this message because you are subscribed 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,* *Piyush Kapoor,* *CSE-IT-BHU*- 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. -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Segmentation fault
You are using too much memory :: long long arr[10003][10003]; -- You received this message because you are subscribed 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 doubt
int main() { char a; printf(%d %d,sizeof(a),sizeof('a')); return 0; } Output: 1 4 why does the expression sizeof('a') evaluates it as an integer,not as a character?? -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 doubt
You didn't understand my question... Why is sizeof() interpreting a constant character literal as ascii??? -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 doubt
Thanks a lot :) -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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: If any one have algorithms for interviews by adnan aziz ebook... Please mail ...
BTW,which book is being referred?? -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 remove return 0
exit(0) is one option..( http://cboard.cprogramming.com/c-programming/118998-exit-0-doubt.html) -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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 query
http://ideone.com/CJxFK give (null) 0.00 -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- You received this message because you are subscribed 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] Re: addition without using arithmetic operators
consider 2 nos a = 1010 b = 1011 ( in bits) take xor of these c = a ^ b; c = 1010 ^1011; c = 0001 idea is if there are 2 1s then make it 0 , if one 1 and one 0 then make it 1; d = ab; when there are 2 ones u have to produce a carry . d = 1010 1011 1000 this d needs to be right shifted so that we can carry on addition , just add n carry problem d = d1 d = 1 now c and d are your 2 new nos a = c ; b = d; proceed until b becomes zero a = 1011 b =1 c = 11011 d = 0 a =c ; a is the final answer Hope it,s clear to you On Thu, Oct 1, 2009 at 10:59 AM, Miroslav Balaz gpsla...@googlemail.com wrote: make into bits and then using logic operators. but this kind of problem sucks. the good way is let A and B are the numbers string s(A,'*'),p(B,'*'); s.append(p); printf( %d + %d=%d,A,B,s.size()); 2009/9/7 ritter amar8...@gmail.com how to add two integers without using arithmetic operators? can anyone help 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 -~--~~~~--~~--~--~---
[algogeeks] Re: Delete the node “next to the node pointed to by a given ptr” in a linked list in a one line code.
ptr-next = ptr-next-next , it will leave dangling pointer but the node wil be deleted On Fri, Jan 23, 2009 at 2:33 PM, Shivang agarwal.shiv...@gmail.com wrote: Hi all, I was stuck in this ques. Delete the node next to the node pointed to by a given ptr in a linked list in a one line code. Can anyone please help me out Thanx 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 -~--~~~~--~~--~--~---