[algogeeks] books
can anyone give me list of books like ( cracking the coding interview ) for placement preparation thanks in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Reading Huge input from the terminal in least time.
If you're working on Linux then there's asynchronous I/O functions that do well.. http://www.gnu.org/s/libc/manual/html_node/Asynchronous-I_002fO.html#Asynchronous-I_002fO http://www.gnu.org/s/libc/manual/html_node/Asynchronous-I_002fO.html#Asynchronous-I_002fOWindows might have similar functionality. On Thu, Apr 21, 2011 at 6:41 AM, Gary Drocella gdroc...@gmail.com wrote: You could just use a pseudo-random number generator to fill in the array. You may also want to consider the data type (each unsigned int would be 4 bytes, where a unsigned char would be 1 byte). Or, If it's truly necessary to read this much data from the console... You could use unix pipes, (cat file.out | ./myprog) pipes in unix shells will redirect from the standard i/o... The format of the file.out should be input0 input1 input2 ... inputn where I guess in your case n = 10^6 That should work, but I don't code in c++ (only c) On Apr 19, 10:11 pm, shubham shubh2...@gmail.com wrote: Hello Geeks, Suppose we have a 2-d array arr[1000][1000] capable of storing 10^6 elements in it. Input is supplied one row at a time. Then what is the best possible way to read this much data in the least amount of time as scanf() or cin takes a lot of time? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] [brain teaser] Pirate Puzzle 21april
* Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? * *Update Your Answers at* : Click Herehttp://dailybrainteaser.blogspot.com/2011/04/pirate-puzzle-21april.html?lavesh=lavesh Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] books
Please mail me 2 , my id is lks.ru...@gmail.com thnX in Advance .. On Thu, Apr 21, 2011 at 12:45 PM, kamlesh yadav kamleshlu2...@gmail.com wrote: can anyone give me list of books like ( cracking the coding interview ) for placement preparation thanks in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Lalit Kishore Sharma, IIIT Allahabad (Amethi Capmus), 6th Sem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Implementing a BTree
Hi, I have to implement BTree and B+ Tree as part of a project. But, I am finding it difficult to do that. Can anyone share his/her code if one has implemented it or share resources where I can find the implementation? Praveen -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] [brain teaser] Pirate Puzzle 21april
the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] [brain teaser] Pirate Puzzle 21april
thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Harshit Agrawal MNNIT Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] [brain teaser] Pirate Puzzle 21april
Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.comwrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Harshit Agrawal MNNIT Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] [brain teaser] Pirate Puzzle 21april
@vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.comwrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Harshit Agrawal MNNIT Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] [brain teaser] Pirate Puzzle 21april
They can still disagree and the pirate would be thrown out as the puzzle states On Thu, Apr 21, 2011 at 3:21 PM, durgaprasad k durga...@gmail.com wrote: @vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.comwrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Harshit Agrawal MNNIT Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] [brain teaser] Pirate Puzzle 21april
So the explanation is:- Lets say,, there were only 2. Then the top guy does not need any vote. He will keep all 100. But the bottom guy can see this. So when 3 people were alive, he will support the 3rd guy. The third guy is greedy and he will keep 99 and give 1 to bottom guy. Bottom fellow will happily take that coin. But, the second guy knows this. So when the 4th guy was alive, he would vote for him and take 1 coin from him. But, the third guy has already figured it out. So he will take whatever the 5th guy offers! Now the 5th guy will give 1 each to 3rd and first. On Thu, Apr 21, 2011 at 3:21 PM, durgaprasad k durga...@gmail.com wrote: @vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.comwrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Harshit Agrawal MNNIT Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Kunal Yadav (http://algoritmus.in/) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] [brain teaser] Pirate Puzzle 21april
Not necessarily. Whatever the senior pirate proposes will have to be accepted by pirate 4th and 2nd (assuming 5th is senior most) otherwise pirate 1st gets everything. So it is oldest pirate's call. He can I guess take it all. Shuaib http://twitter.com/ShuaibKhan http://www.bytehood.com/ On 21-Apr-2011, at 2:51 PM, durgaprasad k durga...@gmail.com wrote: @vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.com wrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Harshit Agrawal MNNIT Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: finding n numbers having particular sum
Thanx @DON, was looking for it for a bit of time... I myself wrote some piece of code though urs is the better one On Apr 19, 10:21 am, Don dondod...@gmail.com wrote: Here is the program with better documentation and a fix for the case when sum is zero. // Number of elements to select from const int setSize = 20; // Unique integers to select from int set[setSize] = { 5,9,1,3,4,2,6,7,11,10,13,15,19,22,25,31,33,37,39,40}; // Desired sum of subset const int sum = 165; // Stores the current subset int rec[setSize]; int recCount = 0; int subset=0; // Find a subset of set which adds to sum void search(int *set, int setSize, int sum) { // If we found a subset, print it if ((sum == 0) recCount) { printf(Subset %d: {%d, ++subset,rec[0]); for(int i = 1; i recCount; ++i) printf(,%d, rec[i]); printf(}\n); } else if (sum 0) { // Consider elements of the set to add to the subset for(int i = 0; i setSize; ++i) { // Include set[i] in the subset rec[recCount++] = set[i]; // Look for remaining elements which add to sum search(set, i, sum-set[i]); // Back out set[i] to try subsets without set[i] --recCount; } } } int main(int argc, char* argv[]) { search(set, setSize, sum); printf(Found %d subsets\n, subset); return 0; } On Apr 18, 11:58 pm, kamlesh yadav kamleshlu2...@gmail.com wrote: @Don thanks, nice one, but can u give a little bit of explanation. On Mon, Apr 18, 2011 at 10:14 PM, Don dondod...@gmail.com wrote: const int setSize = 20; int set[setSize] = { 5,9,1,3,4,2,6,7,11,10,13,15,19,22,25,31,33,37,39,40}; const int sum = 150; int rec[setSize]; int recCount = 0; int subset=0; void search(int *set, int setSize, int sum) { int i; if (sum == 0) { printf(Subset %d: {%d, ++subset,rec[0]); for(i = 1; i recCount; ++i) printf(,%d, rec[i]); printf(}\n); } else if (sum 0) { for(i = 0; i setSize; ++i) { rec[recCount++] = set[i]; search(set, i, sum-set[i]); --recCount; } } } int main(int argc, char* argv[]) { search(set, setSize, sum); return 0; } On Apr 18, 6:16 am, kamlesh yadav kamleshlu2...@gmail.com wrote: given an array of elements (all elements are unique ) , given a sum s find all the subsets having sum s. for ex array {5,9,1,3,4,2,6,7,11,10} sum is 10 possible subsets are {10}, {6,4} ,{7,3} {5,3,2} {6,3,1} etc. there can be many more. also find the total number of these subsets -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/algogeeks?hl=en. -- Kamlesh Kumar Yadav MCA Department of Computer Science Delhi University -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
will crash... :) On Thu, Apr 21, 2011 at 4:14 PM, riti gupta ritigupt...@gmail.com wrote: is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
why?can u please explain? On Thu, Apr 21, 2011 at 4:15 PM, rahul rahulr...@gmail.com wrote: will crash... :) On Thu, Apr 21, 2011 at 4:14 PM, riti gupta ritigupt...@gmail.com wrote: is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
the segment which stores hello may be read only, so writing to it may cause unexpected result. On Thu, Apr 21, 2011 at 6:45 PM, rahul rahulr...@gmail.com wrote: will crash... :) On Thu, Apr 21, 2011 at 4:14 PM, riti gupta ritigupt...@gmail.com wrote: is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
' Hello ' is a literal.. Its allotted memory and a reference is made to 'p' you can not alter value like this... Regards, Keybo -Original message- From: riti gupta Sent: 21/04/2011, 4:14 pm To: algogeeks@googlegroups.com Subject: [algogeeks] is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
char * is pointer to constant data...here...that's y it would crash...dear.. do somedebugging On Thu, Apr 21, 2011 at 4:16 PM, riti gupta ritigupt...@gmail.com wrote: why?can u please explain? On Thu, Apr 21, 2011 at 4:15 PM, rahul rahulr...@gmail.com wrote: will crash... :) On Thu, Apr 21, 2011 at 4:14 PM, riti gupta ritigupt...@gmail.comwrote: is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
yes there is error; first allocate memory for p; On Thu, Apr 21, 2011 at 6:44 AM, riti gupta ritigupt...@gmail.com wrote: is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- [image: motilal.JPG] Thanks Regards...* SUDHIR MISHRA sudhir08.mis...@gmail.com* *IT 3rd YEAR* *Motilal Nehru National institute Of Technology-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. motilal.JPG
Re: [algogeeks]
Than y r we able to do the following main() { char *p=hello; p=bye; } On Thu, Apr 21, 2011 at 4:21 PM, Sudhir mishra sudhir08.mis...@gmail.comwrote: yes there is error; first allocate memory for p; On Thu, Apr 21, 2011 at 6:44 AM, riti gupta ritigupt...@gmail.com wrote: is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- [image: motilal.JPG] Thanks Regards...* SUDHIR MISHRA sudhir08.mis...@gmail.com* *IT 3rd YEAR* *Motilal Nehru National institute Of Technology-ALLAHABAD. * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. motilal.JPG
Re: [algogeeks]
yes p points to the base adress of constant string hello so you cannot change this string . On Thu, Apr 21, 2011 at 4:14 PM, riti gupta ritigupt...@gmail.com wrote: is there any error in following code? main { char *p=hello; p[0]='j'; p[1]='j'; puts(p); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Amit Kumar Singh Software Engineer Samsung India Software Operations Banglore India -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] [brain teaser] Pirate Puzzle 21april
lets consider if there were only 1 pirate. obviously he would take it all for himself and no one would complain. if there were 2 pirates, pirate 2 being the most senior, he would just vote for himself and that would be 50% of the vote, so he’s obviously going to keep all the money for himself. if there were 3 pirates, pirate 3 has to convince at least one other person to join in his plan. s *pirate 3 realizes that if his plan is not adopted he will be executed and they will be left with 2 pirates*. he already knows what happens when there are 2 pirates as we just figured out. pirate 2 takes all the money himself and gives nothing to pirate 1. so pirate 3 proposes that he will take 99 gold coins and give 1 coin to pirate 1. pirate 1 says, well, 1 is better than none, and since i know if i don’t vote for pirate 3, i get nothing, i should vote for this plan. now we know what happens when there are 3 pirates. so what happens with 4? well pirate 4 has to convince 1 other person to join in his plan. he knows if he walks the plank then pirate 3 will get 99 coins and pirate 1 will get 1 coin. pirate 4 could propose giving pirate 1 two coins, and surely pirate 1 would vote for him, since 2 is better than 1. but as he is greedy ,pirate 4 would rather not part with 2 whole coins. he realizes that if he gets executed, then pirate 3’s scenario happens and pirate 2 gets the shaft in that scenario (he gets zero coins). so pirate 4 proposes that he will give 1 coin to pirate 2, and pirate 2 seeing that 1 is better than 0 will obviously vote for this plan. a common objection is that pirate 2 is not guaranteed to vote for this plan since he might hope for the case when there are only 2 pirates and then he gets all the booty. but that is why it is said that the pirates are extremely intelligent. pirate 2 realizes that pirate 3 is smart enough to make the optimal proposal, so he realizes that there will never be 2 pirates left, because 3 doesn’t want to die and we just showed that 3 has a winning proposal. so lets sum up at this point Pirate 1 2 3 4 5 5. ? ? ? ? ? 4. 0 1 0 99 - 3. 1 0 99 - - 2. 0 100 - - - 1.100 On Thu, Apr 21, 2011 at 6:13 AM, Shuaib aries.shu...@gmail.com wrote: Not necessarily. Whatever the senior pirate proposes will have to be accepted by pirate 4th and 2nd (assuming 5th is senior most) otherwise pirate 1st gets everything. So it is oldest pirate's call. He can I guess take it all. Shuaib http://twitter.com/ShuaibKhan http://www.bytehood.com/ On 21-Apr-2011, at 2:51 PM, durgaprasad k durga...@gmail.com wrote: @vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.com agrvaib...@gmail.com wrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma http://xuejiao.ma xuejiao.ma@ http://gmail.comgmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks%2bunsubscr...@googlegroups.com algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en. -- Regards Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com algogeeks@googlegroups.com. To unsubscribe from this group, send email to
[algogeeks] Problem; print the largest subset of negative number in array of integers
Problem; print the largest subset of negative number in array of integers i have code it in following way which is give solution in O(n) and and required memory in O(n) any tell me other method better then this O(n) . pls tell me is it any bug in the code #includestdio.h int count=0,ind=-1,len,i=0; void largestNegSubset(int arr[]) { if(ilen) return ; int t=0; while(arr[i++]0i=len)t++; if(tcount){count=t;ind=i-1;} largestNegSubset(arr); } int main() { int arr[]={1,0,1,-6,-7,-2,-2,4,-3,-5,-6,7,-8,-9}; len=(sizeof(arr)/sizeof(int)); largestNegSubset(arr); for(i=ind-1;i(ind-count-1);i--) printf(%d,,arr[i]); 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.
Re: [algogeeks]
main() { char *p=(char *)hello; p[0]='j'; p[1]='j'; puts(p); return 0; } will run currectlly but u can not change contain of literal because of its type is (const char *) . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
On 21/04/2011 11:55, riti gupta wrote: Than y r we able to do the following main() { char *p=hello; p=bye; } Because you're changing the binding of p, not the value (which is immutable, as explained already). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
@Hary rathor: Your program also crash on my Dev-Cpp (Version 4.9.9.2)..Make sure whether it runs on your PC !! I don't know whether Literal can be type-casted... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
#includestdio.h #includeconio.h int count=0,ind=-1,len,i=0; void largestNegSubset(int arr[]) { if(ilen) return ; int t=0; while(arr[i++]0i=len)t++; if(tcount){count=t;ind=i-1;} largestNegSubset(arr); } int main() { int arr[]={1,0,1,-6,-7,-2,-2,4,-3,-5,-6,7,-8,-9}; len=(sizeof(arr)/sizeof(int)); largestNegSubset(arr); for(i=ind-1;i(ind-count-1);i--) printf(%d,,arr[i]); getch(); 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.
Re: [algogeeks]
@ kunal: above code is not for you i have run this on http://codepad.org/TiOQBKU8 check it then tell me -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] CKY parse tree algorithm
Hello, In the CKY algorithm for PCFGs and finding the most probable parse tree, when exactly can it fail to parse? I didn't think it could but I was informed that I'm mistaken. Thanks, Richard -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
@riti: You can change *char *p=hello;* to *char p[] = hello;* then everything should be fine. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] books
FYI. Someone is starting to translate the Chinese version in http://pro.yeeyan.org/CRACKINGTHECODINGINTERVIEW 2011/4/21 LALIT SHARMA lks.ru...@gmail.com Please mail me 2 , my id is lks.ru...@gmail.com thnX in Advance .. On Thu, Apr 21, 2011 at 12:45 PM, kamlesh yadav kamleshlu2...@gmail.com wrote: can anyone give me list of books like ( cracking the coding interview ) for placement preparation thanks in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Lalit Kishore Sharma, IIIT Allahabad (Amethi Capmus), 6th Sem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Fwd: Fw: Building a Binary tree with XOR
Plz help out the with the below mentioned problem (Query by Someone else, i was not able to understand) Building a Binary tree with XOR Hi All, Before starting any binary tree problem I will be creating such kind of binary tree and will be solving that problem accordingly. From the last few days I am trying to code to build a binary tree with Exclusive Operators. Here I am trying to build the tree in the level order way like all the elements will be placed in the queue in the order of levels so that the final binary tree will be almost complete binary tree. In general the left node will contain the left side tree adress details and right node will contain the right tree details. But the XOR Binary trees will be holding the XOR values of parent and left child in the left node and in the same way the parent and right child will be in the right part. Here I am unable to track the parent of a particular node after the level 3. Does it possible to create a XOR binary tree with the level order mechanism. If possible, could you provide me clues in resolving this problem. My files looks like as below Header file: #includeiostream #includequeue using namespace std; typedef unsigned long pointer; struct BTXNode { int data; struct BTXNode* fleft; struct BTXNode* fright; }; class BTX { struct BTXNode *root; public: BTX() { root=NULL; } struct BTXNode* getNode(int data); int insertAtLeaf(struct BTXNode* node); }; -- CPP file --- #include btf_xor.h struct BTXNode* BTX::getNode(int data) { struct BTXNode* node=new BTXNode(); node-data=data; node-fleft=NULL; node-fright=NULL; return node; } int BTX::insertAtLeaf(struct BTXNode* nd) { coutinsertAtLeaf Data is nd-dataendl; bool set_ind=true; bool right_ind=false; struct BTXNode *parent=NULL; if(!root) { root=nd; return 1; } queueBTXNode* q; q.push(root); q.push(NULL); while(!q.empty() set_ind) { struct BTXNode *temp=q.front(); q.pop(); if(temp) { couttemp-data istemp-dataendl; if(temp-fleft != parent) { struct BTXNode* left=(struct BTXNode*)((pointer)temp- fleft^(pointer)parent); q.push(left); right_ind=true; } else { nd-fleft=(struct BTXNode*)((pointer)temp ^ (pointer)nd-fleft); nd-fright=(struct BTXNode*)((pointer)temp ^ (pointer)nd-fright); //temp-fleft=(struct BTXNode*)((pointer)nd ^ (pointer)parent); temp-fleft=(struct BTXNode*)((pointer)nd ^ (pointer)temp-fleft); right_ind=false; set_ind=false; } if(right_ind) { if(temp-fright != parent) { struct BTXNode* right=(struct BTXNode*)((pointer)temp- fright^(pointer)parent); q.push(right); right_ind=true; } else { nd-fright=(struct BTXNode*)((pointer)temp ^ (pointer)nd-fright); nd-fleft=(struct BTXNode*)((pointer)temp ^ (pointer)nd- fleft); //temp-fright=(struct BTXNode*)((pointer)nd ^ (pointer)parent); temp-fright=(struct BTXNode*)((pointer)nd ^ (pointer)temp- fright); set_ind=false; } } parent=temp; } else { if(!q.empty()) { q.push(NULL); } } } } int main() { BTX btx; btx.insertAtLeaf(btx.getNode(10) ); btx.insertAtLeaf(btx.getNode(8)); btx.insertAtLeaf(btx.getNode(12)); btx.insertAtLeaf(btx.getNode(7)); btx.insertAtLeaf(btx.getNode(9)); btx.insertAtLeaf(btx.getNode(11)); btx.insertAtLeaf(btx.getNode(13)); return 0; } Regards Sunil -- Regards Ravi Maggon -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Problem; print the largest subset of negative number in array of integers
I think O(n) is the best time complexity. Try to think about one sequence with all negative numbers or positive numbers. we can't get the full information without one time iteration, or we can just say the data reading time will cost O(n). 2011/4/21 hary rathor harry.rat...@gmail.com Problem; print the largest subset of negative number in array of integers i have code it in following way which is give solution in O(n) and and required memory in O(n) any tell me other method better then this O(n) . pls tell me is it any bug in the code #includestdio.h int count=0,ind=-1,len,i=0; void largestNegSubset(int arr[]) { if(ilen) return ; int t=0; while(arr[i++]0i=len)t++; if(tcount){count=t;ind=i-1;} largestNegSubset(arr); } int main() { int arr[]={1,0,1,-6,-7,-2,-2,4,-3,-5,-6,7,-8,-9}; len=(sizeof(arr)/sizeof(int)); largestNegSubset(arr); for(i=ind-1;i(ind-count-1);i--) printf(%d,,arr[i]); 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.
[algogeeks] A Global MBA Experience
*A Global MBA Experience Latin America – Europe - Asia. Top ranked MBA http://bit.ly/AsianEdu http://bit.ly/AsianEdu -- * If you would like to get daily pictures We've started a Google Group to allow our visitors to get daily funny and Crazy Pictures , You can join this group for free , go to... *http://groups.google.com/group/WomenForum/subscribe* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] books
Thank you On Thu, Apr 21, 2011 at 8:50 PM, Rujin Cao drizzle...@gmail.com wrote: FYI. Someone is starting to translate the Chinese version in http://pro.yeeyan.org/CRACKINGTHECODINGINTERVIEW 2011/4/21 LALIT SHARMA lks.ru...@gmail.com Please mail me 2 , my id is lks.ru...@gmail.com thnX in Advance .. On Thu, Apr 21, 2011 at 12:45 PM, kamlesh yadav kamleshlu2...@gmail.com wrote: can anyone give me list of books like ( cracking the coding interview ) for placement preparation thanks in advance. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Lalit Kishore Sharma, IIIT Allahabad (Amethi Capmus), 6th Sem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thanks and Regards, Manish Pathak ** TimesJobs.com Mo. 9015687266 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] [brain teaser] Pirate Puzzle 21april
I think the original statement says that The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. So the pirate proposing the distribution can't vote for himself. -- Shuaib http://twitter.com/ShuaibKhan http://bytehood.com/ On Thursday, April 21, 2011 at 4:43 PM, vaibhav shukla wrote: lets consider if there were only 1 pirate. obviously he would take it all for himself and no one would complain. if there were 2 pirates, pirate 2 being the most senior, he would just vote for himself and that would be 50% of the vote, so he’s obviously going to keep all the money for himself. if there were 3 pirates, pirate 3 has to convince at least one other person to join in his plan. s pirate 3 realizes that if his plan is not adopted he will be executed and they will be left with 2 pirates. he already knows what happens when there are 2 pirates as we just figured out. pirate 2 takes all the money himself and gives nothing to pirate 1. so pirate 3 proposes that he will take 99 gold coins and give 1 coin to pirate 1. pirate 1 says, well, 1 is better than none, and since i know if i don’t vote for pirate 3, i get nothing, i should vote for this plan. now we know what happens when there are 3 pirates. so what happens with 4? well pirate 4 has to convince 1 other person to join in his plan. he knows if he walks the plank then pirate 3 will get 99 coins and pirate 1 will get 1 coin. pirate 4 could propose giving pirate 1 two coins, and surely pirate 1 would vote for him, since 2 is better than 1. but as he is greedy ,pirate 4 would rather not part with 2 whole coins. he realizes that if he gets executed, then pirate 3’s scenario happens and pirate 2 gets the shaft in that scenario (he gets zero coins). so pirate 4 proposes that he will give 1 coin to pirate 2, and pirate 2 seeing that 1 is better than 0 will obviously vote for this plan. a common objection is that pirate 2 is not guaranteed to vote for this plan since he might hope for the case when there are only 2 pirates and then he gets all the booty. but that is why it is said that the pirates are extremely intelligent. pirate 2 realizes that pirate 3 is smart enough to make the optimal proposal, so he realizes that there will never be 2 pirates left, because 3 doesn’t want to die and we just showed that 3 has a winning proposal. so lets sum up at this point Pirate 1 2 3 4 5 5. ? ? ? ? ? 4. 0 1 0 99 - 3. 1 0 99 - - 2. 0 100 - - - 1.100 On Thu, Apr 21, 2011 at 6:13 AM, Shuaib aries.shu...@gmail.com wrote: Not necessarily. Whatever the senior pirate proposes will have to be accepted by pirate 4th and 2nd (assuming 5th is senior most) otherwise pirate 1st gets everything. So it is oldest pirate's call. He can I guess take it all. Shuaib http://twitter.com/ShuaibKhan http://www.bytehood.com/ On 21-Apr-2011, at 2:51 PM, durgaprasad k durga...@gmail.com wrote: @vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.com wrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group,
Re: [algogeeks] [brain teaser] Pirate Puzzle 21april
nopesdats not the point.in every election one can vote for himself also On Thu, Apr 21, 2011 at 11:12 PM, Shuaib aries.shu...@gmail.com wrote: I think the original statement says that * The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. * So the pirate proposing the distribution can't vote for himself. -- Shuaib http://twitter.com/ShuaibKhan http://bytehood.com/ On Thursday, April 21, 2011 at 4:43 PM, vaibhav shukla wrote: lets consider if there were only 1 pirate. obviously he would take it all for himself and no one would complain. if there were 2 pirates, pirate 2 being the most senior, he would just vote for himself and that would be 50% of the vote, so he’s obviously going to keep all the money for himself. if there were 3 pirates, pirate 3 has to convince at least one other person to join in his plan. s *pirate 3 realizes that if his plan is not adopted he will be executed and they will be left with 2 pirates*. he already knows what happens when there are 2 pirates as we just figured out. pirate 2 takes all the money himself and gives nothing to pirate 1. so pirate 3 proposes that he will take 99 gold coins and give 1 coin to pirate 1. pirate 1 says, well, 1 is better than none, and since i know if i don’t vote for pirate 3, i get nothing, i should vote for this plan. now we know what happens when there are 3 pirates. so what happens with 4? well pirate 4 has to convince 1 other person to join in his plan. he knows if he walks the plank then pirate 3 will get 99 coins and pirate 1 will get 1 coin. pirate 4 could propose giving pirate 1 two coins, and surely pirate 1 would vote for him, since 2 is better than 1. but as he is greedy ,pirate 4 would rather not part with 2 whole coins. he realizes that if he gets executed, then pirate 3’s scenario happens and pirate 2 gets the shaft in that scenario (he gets zero coins). so pirate 4 proposes that he will give 1 coin to pirate 2, and pirate 2 seeing that 1 is better than 0 will obviously vote for this plan. a common objection is that pirate 2 is not guaranteed to vote for this plan since he might hope for the case when there are only 2 pirates and then he gets all the booty. but that is why it is said that the pirates are extremely intelligent. pirate 2 realizes that pirate 3 is smart enough to make the optimal proposal, so he realizes that there will never be 2 pirates left, because 3 doesn’t want to die and we just showed that 3 has a winning proposal. so lets sum up at this point Pirate 1 2 3 4 5 5. ? ? ? ? ? 4. 0 1 0 99 - 3. 1 0 99 - - 2. 0 100 - - - 1.100 On Thu, Apr 21, 2011 at 6:13 AM, Shuaib aries.shu...@gmail.com wrote: Not necessarily. Whatever the senior pirate proposes will have to be accepted by pirate 4th and 2nd (assuming 5th is senior most) otherwise pirate 1st gets everything. So it is oldest pirate's call. He can I guess take it all. Shuaib http://twitter.com/ShuaibKhan http://www.bytehood.com/ On 21-Apr-2011, at 2:51 PM, durgaprasad k durga...@gmail.com wrote: @vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.com agrvaib...@gmail.com wrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma http://xuejiao.maxuejiao.ma @ http://gmail.comgmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com algogeeks@googlegroups.com. To
[algogeeks] Ebooks Sites
Hello people please share sites from where good programming ebooks can be downloaded... i use library.nu and 4shared.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.
[algogeeks] Flipping Coins
Pls have a look at this Question on codechef http://www.codechef.com/problems/FLIPCOIN/ i tried this using Segment tree... i implemented segment updating properly but dont know how to do segment Querying in this particular Question although point Querying is easy.. and please suggest links and ebooks for topics such as segment tree. Interval tree , Binary Indexed tree , Suffix trees(Other than Topcoder Tutorials) This is how i implemented Segment updating: void update(int beg,int end,int ind)//segment updating { if(begB || endA) return; if(beg=A end=B) m[ind]+=k; else { update(beg,((beg+end)1),(ind1)); update(1+((beg+end)1),end,1+(ind1)); } } may be u need to change for Querying -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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]
http://huggallart.com/surprise11.html -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Ebooks Sites
www.etwist.net On Fri, Apr 22, 2011 at 12:53 AM, KK kunalkapadi...@gmail.com wrote: Hello people please share sites from where good programming ebooks can be downloaded... i use library.nu and 4shared.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. -- **With Regards Deoki Nandan Vishwakarma IITR MCA Mathematics Department* * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] [brain teaser] Pirate Puzzle 21april
excellent analysis! On Thu, Apr 21, 2011 at 7:43 PM, vaibhav shukla vaibhav200...@gmail.com wrote: lets consider if there were only 1 pirate. obviously he would take it all for himself and no one would complain. if there were 2 pirates, pirate 2 being the most senior, he would just vote for himself and that would be 50% of the vote, so he’s obviously going to keep all the money for himself. if there were 3 pirates, pirate 3 has to convince at least one other person to join in his plan. s pirate 3 realizes that if his plan is not adopted he will be executed and they will be left with 2 pirates. he already knows what happens when there are 2 pirates as we just figured out. pirate 2 takes all the money himself and gives nothing to pirate 1. so pirate 3 proposes that he will take 99 gold coins and give 1 coin to pirate 1. pirate 1 says, well, 1 is better than none, and since i know if i don’t vote for pirate 3, i get nothing, i should vote for this plan. now we know what happens when there are 3 pirates. so what happens with 4? well pirate 4 has to convince 1 other person to join in his plan. he knows if he walks the plank then pirate 3 will get 99 coins and pirate 1 will get 1 coin. pirate 4 could propose giving pirate 1 two coins, and surely pirate 1 would vote for him, since 2 is better than 1. but as he is greedy ,pirate 4 would rather not part with 2 whole coins. he realizes that if he gets executed, then pirate 3’s scenario happens and pirate 2 gets the shaft in that scenario (he gets zero coins). so pirate 4 proposes that he will give 1 coin to pirate 2, and pirate 2 seeing that 1 is better than 0 will obviously vote for this plan. a common objection is that pirate 2 is not guaranteed to vote for this plan since he might hope for the case when there are only 2 pirates and then he gets all the booty. but that is why it is said that the pirates are extremely intelligent. pirate 2 realizes that pirate 3 is smart enough to make the optimal proposal, so he realizes that there will never be 2 pirates left, because 3 doesn’t want to die and we just showed that 3 has a winning proposal. so lets sum up at this point Pirate 1 2 3 4 5 5. ? ? ? ? ? 4. 0 1 0 99 - 3. 1 0 99 - - 2. 0 100 - - - 1.100 On Thu, Apr 21, 2011 at 6:13 AM, Shuaib aries.shu...@gmail.com wrote: Not necessarily. Whatever the senior pirate proposes will have to be accepted by pirate 4th and 2nd (assuming 5th is senior most) otherwise pirate 1st gets everything. So it is oldest pirate's call. He can I guess take it all. Shuaib http://twitter.com/ShuaibKhan http://www.bytehood.com/ On 21-Apr-2011, at 2:51 PM, durgaprasad k durga...@gmail.com wrote: @vaibhav : if they dont agree for 1 gold icon they will be thrown out. so they will accept the 1 gold coin to stay on . On Thu, Apr 21, 2011 at 3:10 PM, vaibhav agrawal agrvaib...@gmail.com wrote: Why the two pirates would agree when they are getting only one coins each? On Thu, Apr 21, 2011 at 3:05 PM, harshit agrawal hagrawal.250...@gmail.com wrote: thwy will be shared according to senior most pirate(5th)=98 4th =0 3rd =1 2nd=0 1st =1 On Thu, Apr 21, 2011 at 2:54 PM, Anders Ma xuejiao...@gmail.com wrote: the coins will be shared the way the oldest pirate proposes. On Thu, Apr 21, 2011 at 3:51 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Pirate Puzzle 5 pirates of different ages have a treasure of 100 gold coins. On their ship, they decide to split the coins using this scheme: The oldest pirate proposes how to share the coins, and all pirates remaining will vote for or against it. If 50% or more of the pirates vote for it, then the coins will be shared that way. Otherwise, the pirate proposing the scheme will be thrown overboard, and the process is repeated with the pirates that remain. Assuming that all 5 pirates are intelligent, rational, greedy, and do not wish to die, (and are rather good at math for pirates) what will happen? Update Your Answers at : Click Here Solution: Will be updated after 1 day -- Never explain yourself. Your friends don’t need it and your enemies won’t believe it . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Anders -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.