Re: [algogeeks] help with o/p why 0 comes???
on my system every time o/p is 0 using ubuntu 10.04 ,gcc compiler On Mon, Mar 4, 2013 at 7:34 AM, rohit jangid rohit.nsi...@gmail.com wrote: output for me for the previous snippet localhost:slingshot rohitjangid$ ./a.out 1799476872 1799474584 localhost:slingshot rohitjangid$ ./a.out 1710327432 1710325144 localhost:slingshot rohitjangid$ ./a.out 1856128648 1856126360 localhost:slingshot rohitjangid$ ./a.out 1724065416 1724063128 On Mon, Mar 4, 2013 at 7:33 AM, rohit jangid rohit.nsi...@gmail.comwrote: yeah true . one interesting thing I noticed is that if you run this code #includestdio.h int main() { int i = 0; do { printf (%d\n,(float)1); }while(i++ 1); return 0; } one would expect same output in both the rows but surprisingly it came different for me every time . any clues .. why ? On Fri, Mar 1, 2013 at 12:05 PM, Karthikeyan V.B kartmu...@gmail.comwrote: O/p will not be 0. 1.00 is the result which when read as %d takes the decimal value of float 1.00 stored in memory - it will not be 1.00 or 0. Since float is not stored as direct binary in memory as integer is stored, instead there's a separate procedure for storing float as binary in memory -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Rohit Jangid Graduate Deptt. of Computer Engineering NSIT, Delhi University, India -- Rohit Jangid Graduate Deptt. of Computer Engineering NSIT, Delhi University, India -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[algogeeks] separate coins into heaps of similar weights using balance in minimum comparisons
There are 8 coins in a bag . 3 coin weights x kg 3 coins weights y kg 2 coins weights z kg 2 coins weights w kg You have to separate them into separate heaps according to their weights in minimum comparisons using weighing balance. -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] Re: separate coins into heaps of similar weights using balance in minimum comparisons
@dave you are correct but language of question implies--- out of 8 coins 3 taken together weigh x,again 3 coins taken out of 8 have y as weight . This shows that one or more coins out of 3 (weight x) may be same as those considered for weight y as so on for z and w. On Sat, Mar 2, 2013 at 2:39 AM, Dave dave_and_da...@juno.com wrote: @Maddy: I'm a little confused because there are 8 coins in the bag but 3 + 3 + 2 + 2 = 10 coins are grouped by weight. Dave On Friday, March 1, 2013 1:15:03 PM UTC-6, maddy wrote: There are 8 coins in a bag . 3 coin weights x kg 3 coins weights y kg 2 coins weights z kg 2 coins weights w kg You have to separate them into separate heaps according to their weights in minimum comparisons using weighing balance. -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[algogeeks] help with o/p why 0 comes???
code snippet: *int main() { printf (%d\n,(float)((int)(3.5/2))); return 0; }* -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] help with o/p why 0 comes???
thank you for pointing out that format was the key point. On Fri, Mar 1, 2013 at 1:19 AM, gmagog...@gmail.com gmagog...@gmail.comwrote: I think this is because of type mismatch. You are enforcing your program to read a floating point number in the way of reading a integer. And they have totally different format. If you have -Wall turned on, you should see a warning. Yanan Cao On Thu, Feb 28, 2013 at 1:41 PM, Shubham Sandeep s.shubhamsand...@gmail.com wrote: code snippet: *int main() { printf (%d\n,(float)((int)(3.5/2))); return 0; }* -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] how does this code achieve SIGSEGV
thank you sir, very well explained . On Sat, Dec 22, 2012 at 12:47 PM, saurabh singh saurab...@gmail.com wrote: **p; * Explanation: By default C thinks everything is an int. So p is a global variable of type *pointer to an int.*Now like other global variables it is very very very very likely that the compiler will associate p with an address that is *0.*Or in terms of pointers it is *NULL.* That is printf(%d\n,p) should give 0. **p=0;* * * What happens when you do **(some_ptr)? *The address stored by some_ptr is referred to. So when we try to do **p=0 the address pointed by p is referred,which is NULL,and by the law of the land trying to read/write from memory with address NULL is sin. *So you get segmentation fault. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Sat, Dec 22, 2012 at 10:52 AM, Saurabh Paliwal saurabh.paliwa...@gmail.com wrote: I am afraid both of you are incorrect.. 1. since the code modified by you will compile but give sigsegv anyway. 2. The statement *p = 0; has nothing to do with the random address you are talking about. On Mon, Dec 17, 2012 at 7:25 PM, Prakhar Jain jprakha...@gmail.comwrote: You are initialising random memory address with 0, which OS doesn't allow. On 12/17/12, Shubham Sandeep s.shubhamsand...@gmail.com wrote: how does this code achieve SIGSEGV code: *p;main(){*p=0;} -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- -- -- Prakhar Jain IIIT Allahabad B.Tech IT 4th Year Mob no: +91 9454992196 E-mail: rit2009...@iiita.ac.in jprakha...@gmail.com -- -- -Saurabh Paliwal B-Tech. Comp. Science and Engg. IIT ROORKEE -- -- -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. --
[algogeeks] how does this code achieve SIGSEGV
how does this code achieve SIGSEGV code: *p;main(){*p=0;} -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. --
Re: [algogeeks] Re: adobe apti question
agreed On Mon, Dec 17, 2012 at 10:03 AM, marti amritsa...@gmail.com wrote: Yes Rahul Sharma. you are right. the ans is 1and3 or 2and3 On Sunday, December 16, 2012 11:18:57 PM UTC+5:30, rahul sharma wrote: A causes B or C, but not both F occurs only if B occurs D occurs if B or C occurs E occurs only if C occurs J occurs only if E or F occurs D causes G,H or both H occurs if E occurs G occurs if F occurs 6. If A occurs which of the following must occurs I. F and G II. E and H III. D (a) I only (b) II only (c) III only (d) I,II, III (e) I II (or) II III but not both Ans. (e) E option should be or 113 am i ryt??? A- b or c. if A-Bthen B-fg and Delse if A-C ,then c-eh and c-d am i ryt -- -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. --
Re: [algogeeks] Re: adobe apti question
according to me option c holds Reason:it is either that FG or EH pair occurs but both pairs cannot occur as one is an oucome of B while other holds if C occurs. since either B or C (but not both) may follow A... so point prooved. but D will always be there weather B or C follows after A. since must occur is asked my answer is option C On Sun, Dec 16, 2012 at 11:39 PM, marti amritsa...@gmail.com wrote: Yes I feel (e) is the right option. On Sunday, December 16, 2012 11:18:57 PM UTC+5:30, rahul sharma wrote: A causes B or C, but not both F occurs only if B occurs D occurs if B or C occurs E occurs only if C occurs J occurs only if E or F occurs D causes G,H or both H occurs if E occurs G occurs if F occurs 6. If A occurs which of the following must occurs I. F and G II. E and H III. D (a) I only (b) II only (c) III only (d) I,II, III (e) I II (or) II III but not both Ans. (e) E option should be or 113 am i ryt??? A- b or c. if A-Bthen B-fg and Delse if A-C ,then c-eh and c-d am i ryt -- -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. --
Re: [algogeeks] Re: Amazon interview Question
hello all... anwer to previous example would be 5436827 instead of 5436872please correct it :) On Sun, Dec 16, 2012 at 11:48 PM, marti amritsa...@gmail.com wrote: Here is what you do EG: 5436782 ans is 5436872 how did we arrive? FInd least index i, such that a[i-1] = a[i] starting from rigthmost 5436782 (8) Now , Find least index j such that a[j-1] = a[i-1]: 5436782 (7) swap them = 5436872 Now swap all values between i and j. Pseudocode in Python: *def get_next(a):* *N = len(a)* *i = len(a)-1* * * *while a[i-1] = a[i]:* *i -= 1* * * *j = N* * * *while a[j-1] = a[i-1]:* *j -= 1* * * *a[i-1], a[j-1] = a[j-1], a[i-1]* * * *i += 1* *j = N* * * *while i j:* *a[i-1], a[j-1] = a[j-1], a[i-1]* *i+=1* *j-=1* * * *return a* Source: http://nicolas-lara.blogspot.in/2009/01/permutations.html On Friday, December 14, 2012 11:56:16 AM UTC+5:30, tapan rathi wrote: For a given number, find the next greatest number which is just greater than previous one and made up of same digits. -- -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. --
[algogeeks] plz explain output y it is 1212
#includestdio.h main() { printf ( \%\d\ , 12 ) ; printf ( \%\ d\ , 12 ) ; } -- Regards, SHUBHAM SANDEEP IT 3rd yr. NIT ALD. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Explain the output of this code:
#includestdio.h main() { int a[] = {0,1,2,3,4}; int *p[] = {a,a+1,a+2,a+3,a+4}; int **pp= p; printf(%d, %d, %d , *pp-a, pp-p, **pp); pp++; pp++;; ++pp; *++pp; printf(%d, %d, %d , pp-p, *pp-a, **pp); } output:0 ,0 ,0 ,4 ,4 ,4 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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
@guneesh your code fails to keep order b/w 3 and 4 in the above example On Fri, Jun 15, 2012 at 2:40 PM, Guneesh Paul Singh gunees...@gmail.comwrote: void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else if(a[j]0a[i]0) { swap(a,j,i); } else { if(a[j]0) j++; else i++; } } } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Directi Question
wat constraints does dis bring in the question... Also the books are arranged in a certain order and this order must never be changed. does this imply --- a student gets only consecutivly numbered book if not then sort the array B in decreasing order in Onlogn take another array S of k elements traverse B(sorted) S[i]=B[i] when first k elemnts traversed then traverse again k elemnts of B and S[2*k-i]+=B[i])...again S[i-2*k]+=B[i][.so on till B is traversed completely.. On Sat, Jun 16, 2012 at 2:22 AM, Hemesh Singh hemesh.mn...@gmail.comwrote: At first look it appears to be a simple problem of discrete binary search. Take sum of b[i] as the upper_bound and 0 as the lower bound. Then apply a simple binary search for the number of pages that can be given to a student. Complexity : O(N log( sum( B ) ) ) On Thu, Jun 14, 2012 at 12:26 PM, algogeek dayanidhi.haris...@gmail.comwrote: In a library there are N books with the number of pages in i th book given by bi . These books are to be distributed among K students such that the difference between the largest sum of pages in the books assigned to any student and the smallest sum of number of pages in the books assigned to any student is minimum for the given input. Also the books are arranged in a certain order and this order must never be changed. For eg: suppose B[ ] contains the number of pages in each book. then N=6 K=3 B={3,7,8,2,6,4} then the output will be 0 as we can give book 1 and 2 to student 1 and book 3 and 4 to student 2 and the remaining to student 3. That makes 10 pages for student 1 10 for 2 and 10 for 3 and thus the difference is 0 similarly if B={3,6,8,2,6,4} then the minimum difference will be 1 . -- 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/-/JjKITS_gN9UJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Hemesh singh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.