Re: [algogeeks] Amazon
for the 1st: Divide the base into 5 segments and join the 4 points on the base to the vertex opposite to the base. The 5 triangles formed have equal area because area=1/2 * base * altitude -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon
The above solution I posted was for question 2 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon
FOR question1 it returns no of set bits of N. On 7/19/11, oppilas . jatka.oppimi...@gmail.com wrote: For 3rd, if we only want winner, Then 1110 players must lose. So total 1110 games. On Tue, Jul 19, 2011 at 10:37 AM, sagar pareek sagarpar...@gmail.comwrote: 1. Let's say S=D=N repeat D=(floor)D/2; S=S-D; till D=0 From the above logic, figure out which algorithm is followed by 'S' 2. How can you divide a triangle, to 5 equal triangles? 3. There are players for a chess tournament, having every game as a knock out game (a player will be out of the tournament if he/she loses a game), how many games need to be conducted to determine a winner of the tournament. -- Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Somnath 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.
Re: [algogeeks] Amazon
FOR question1 it returns no of set bits of N. On 7/19/11, SAMM somnath.nit...@gmail.com wrote: FOR question1 it returns no of set bits of N. On 7/19/11, oppilas . jatka.oppimi...@gmail.com wrote: For 3rd, if we only want winner, Then 1110 players must lose. So total 1110 games. On Tue, Jul 19, 2011 at 10:37 AM, sagar pareek sagarpar...@gmail.comwrote: 1. Let's say S=D=N repeat D=(floor)D/2; S=S-D; till D=0 From the above logic, figure out which algorithm is followed by 'S' 2. How can you divide a triangle, to 5 equal triangles? 3. There are players for a chess tournament, having every game as a knock out game (a player will be out of the tournament if he/she loses a game), how many games need to be conducted to determine a winner of the tournament. -- Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Somnath Singh -- Somnath 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.
Re: [algogeeks] Amazon
I think equal is referred as congruent. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Amazon
hey frnds :) isn't the first one is zero knapsack problem? On Tue, Jul 19, 2011 at 11:42 AM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: I think equal is referred as congruent. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Some basic bit fiddling
ok On Tue, Jul 19, 2011 at 11:05 AM, Neeraj Gupta neeraj.gupta...@gmail.comwrote: Sagar, when we shift a variable beyond it's width,then output becomes dependent on the compiler,so it is undefined behavior. In Dev Cpp, I was getting 4 as an output.but there was a warning that left shift is greater than the width of the variable.So I checked on ideone http://ideone.com/Dwof8 On Tue, Jul 19, 2011 at 10:29 AM, sagar pareek sagarpar...@gmail.comwrote: anybody pls if know give the answer On Tue, Jul 19, 2011 at 8:02 AM, Neeraj Gupta neeraj.gupta...@gmail.comwrote: UB. http://ideone.com/Dwof8 On Tue, Jul 19, 2011 at 12:26 AM, Ankur Khurana ankur.kkhur...@gmail.com wrote: please try this cout(134); // gives output 0 int i=1; i=i34; couti ; //gives 4 as out put , why ? -- Ankur Khurana Computer Science , 4th year Netaji Subhas Institute Of Technology Delhi. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Ever growing sorted linked list
hey check my algo...i mentioned all the possible cases :) On Tue, Jul 19, 2011 at 11:31 AM, oppilas . jatka.oppimi...@gmail.comwrote: Yes we can avoid integer comparison. But for jumping we will need to check whether the next node is null or not. So, depending upon the jump size, the number of comparison in worst case can be very large if our jump size is increasing exponentially. So, why not just compare with the next node instead of jumping. On Tue, Jul 19, 2011 at 10:47 AM, sunny agrawal sunny816.i...@gmail.comwrote: yes Alok u r right that in any case we will traverse k times if k is the position if the element that need to searched but by jumping we can save the time of avoiding unnecessary comparisions On Tue, Jul 19, 2011 at 10:44 AM, Alok Prakash alok251...@gmail.comwrote: If i am not wrong, in a linked list to move to any number of position, say n, we have to traverse all intermediate nodes of the linked list. So, it does not matter if we are moving pointer by 2,4,8,... positions, we have to scan all intermediate nodes. Is it not a simple searching On Tue, Jul 19, 2011 at 9:17 AM, sumit sumitispar...@gmail.com wrote: Here is the idea I was thinking of: - start from the root: if(root-data k) move to position 2 in the list. - in this way every time move the pointer to the position double the current position and compare th eelement of node with k( moving here is form 1 - 2 , 2-4, 4-8 ,8-16 ..) - suppose you found a certain node at position n whose node-data k , then now u only have to search for k between index n/2 to n (i.e. if you found 16th element k then search for k between 8th and 16ht element).. correct me if any flaws. On Jul 19, 3:38 am, Dumanshu duman...@gmail.com wrote: @Gaurav: Ever Increasing means that you don't know the length of the list. So you have to assume some index n, traverse the list upto that point and check the results. If not found increment the n to some higher value. We are basically trying to improve the complexity by taking higher and higher jumps for n. On Jul 19, 2:03 am, Gaurav Popli abeygau...@gmail.com wrote: yeah...im saying to reach position n at which k is placed we have to trverse n positions from head or not...?? and i didnt understand the use of ever increasing...please elaborate on it.. On Tue, Jul 19, 2011 at 2:08 AM, Dumanshu duman...@gmail.com wrote: @Swathi: plz give the TC of ur algo (exponential plus log) On Jul 18, 10:14 pm, Swathi chukka.swa...@gmail.com wrote: The solution to this problem will be a combination of exponential increase and the binary search.. start = 0; end = 0; index =0; middle = 0; while (1) { if(a[start] == data) return start; if(a[end] == data) return end; if(data end) { start = end; end = pow(start,2); // here we are consider exponential for faster search. // no need to check any boundary conditions as the array is infinite continue; } else { // do binary search between start index and end index because data is inbetween a[start] and a[end] } } Hope this helps... On Mon, Jul 18, 2011 at 10:32 PM, Gaurav Popli gpgaurav.n...@gmail.comwrote: i dont understand it..if k is at position an let supposeso to check at that position dont you have to traverse till that position ...is thr anything else than the head of list...??or i understood wrongly...?? On Mon, Jul 18, 2011 at 9:55 PM, sagar pareek sagarpar...@gmail.com wrote: Update on 2nd line 2.if( ptr2=ptr1-next-next...(5 or 10 times) ) goto 3. else make linear search till NULL encounter and exit with the solution On Mon, Jul 18, 2011 at 7:41 PM, sagar pareek sagarpar...@gmail.com wrote: i have one approach :- first compare root-data and k if k is very much greater than root-data then set next=5or10 ur choice else set next 2or3 ur choice take two pointers ptr1 and ptr2 now lets take k is much greater than root-data then 1. set ptr1=root //initially 2. if( ptr2=ptr1-next-next...(5 or 10 times) ) else make linear search till NULL encounter 3. if ptr2-data==k return its position 4. else if (ptr2-datak) set ptr1=ptr2 goto 2 5. else traverse the ptr1 upto ptr2, if found return its position else return fail if anyone has more efficient solution then pls tell :) On Mon, Jul 18, 2011 at 6:53 PM, Dumanshu duman...@gmail.com wrote: You have a sorted linked list of integers of some length you don't know and it keeps on increasing. You are given a number k. Print the position of the number k. Basically, you have to search for number k in the ever growing sorted list
[algogeeks] Re: Ever growing sorted linked list
Some please give the TC for exponential + logarithmic search method pointed out by Swathi. On Jul 19, 11:51 am, Ankur Khurana ankur.kkhur...@gmail.com wrote: @sagar: you might have proposed a solution but it ever occured to you that (ptr-next)-next means that you have gone through two diferent nodes. For saving one comparison , we are doing lot of un necessary computations which , IMHO is not good or feasible . Linked list are not made for searching purpose, for that arrays were made. On Tue, Jul 19, 2011 at 12:13 PM, sagar pareek sagarpar...@gmail.comwrote: hey check my algo...i mentioned all the possible cases :) On Tue, Jul 19, 2011 at 11:31 AM, oppilas . jatka.oppimi...@gmail.comwrote: Yes we can avoid integer comparison. But for jumping we will need to check whether the next node is null or not. So, depending upon the jump size, the number of comparison in worst case can be very large if our jump size is increasing exponentially. So, why not just compare with the next node instead of jumping. On Tue, Jul 19, 2011 at 10:47 AM, sunny agrawal sunny816.i...@gmail.comwrote: yes Alok u r right that in any case we will traverse k times if k is the position if the element that need to searched but by jumping we can save the time of avoiding unnecessary comparisions On Tue, Jul 19, 2011 at 10:44 AM, Alok Prakash alok251...@gmail.comwrote: If i am not wrong, in a linked list to move to any number of position, say n, we have to traverse all intermediate nodes of the linked list. So, it does not matter if we are moving pointer by 2,4,8,... positions, we have to scan all intermediate nodes. Is it not a simple searching On Tue, Jul 19, 2011 at 9:17 AM, sumit sumitispar...@gmail.com wrote: Here is the idea I was thinking of: - start from the root: if(root-data k) move to position 2 in the list. - in this way every time move the pointer to the position double the current position and compare th eelement of node with k( moving here is form 1 - 2 , 2-4, 4-8 ,8-16 ..) - suppose you found a certain node at position n whose node-data k , then now u only have to search for k between index n/2 to n (i.e. if you found 16th element k then search for k between 8th and 16ht element).. correct me if any flaws. On Jul 19, 3:38 am, Dumanshu duman...@gmail.com wrote: @Gaurav: Ever Increasing means that you don't know the length of the list. So you have to assume some index n, traverse the list upto that point and check the results. If not found increment the n to some higher value. We are basically trying to improve the complexity by taking higher and higher jumps for n. On Jul 19, 2:03 am, Gaurav Popli abeygau...@gmail.com wrote: yeah...im saying to reach position n at which k is placed we have to trverse n positions from head or not...?? and i didnt understand the use of ever increasing...please elaborate on it.. On Tue, Jul 19, 2011 at 2:08 AM, Dumanshu duman...@gmail.com wrote: @Swathi: plz give the TC of ur algo (exponential plus log) On Jul 18, 10:14 pm, Swathi chukka.swa...@gmail.com wrote: The solution to this problem will be a combination of exponential increase and the binary search.. start = 0; end = 0; index =0; middle = 0; while (1) { if(a[start] == data) return start; if(a[end] == data) return end; if(data end) { start = end; end = pow(start,2); // here we are consider exponential for faster search. // no need to check any boundary conditions as the array is infinite continue; } else { // do binary search between start index and end index because data is inbetween a[start] and a[end] } } Hope this helps... On Mon, Jul 18, 2011 at 10:32 PM, Gaurav Popli gpgaurav.n...@gmail.comwrote: i dont understand it..if k is at position an let supposeso to check at that position dont you have to traverse till that position ...is thr anything else than the head of list...??or i understood wrongly...?? On Mon, Jul 18, 2011 at 9:55 PM, sagar pareek sagarpar...@gmail.com wrote: Update on 2nd line 2. if( ptr2=ptr1-next-next...(5 or 10 times) ) goto 3. else make linear search till NULL encounter and exit with the solution On Mon, Jul 18, 2011 at 7:41 PM, sagar pareek sagarpar...@gmail.com wrote: i have one approach :- first compare root-data and k if k is very much greater than root-data then set next=5or10 ur choice else set next 2or3 ur choice take two pointers ptr1 and ptr2 now lets take k is much greater than root-data then 1. set ptr1=root //initially 2. if( ptr2=ptr1-next-next...(5
[algogeeks] Re: Amazon
What is the answer to the first one? On Jul 19, 10:07 am, sagar pareek sagarpar...@gmail.com wrote: 1. Let's say S=D=N repeat D=(floor)D/2; S=S-D; till D=0 From the above logic, figure out which algorithm is followed by 'S' 2. How can you divide a triangle, to 5 equal triangles? 3. There are players for a chess tournament, having every game as a knock out game (a player will be out of the tournament if he/she loses a game), how many games need to be conducted to determine a winner of the tournament. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Puzzle[Google] Can be Solved programatically as well
Ans. *German* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: MICROSOFT
@Surender: sorry, i had missed a case. We need a 3 way comparison. heres the correct version btree* max_tree(btree *root) { if(root == NULL) return root; btree * current = root; while(current-right != NULL) { current = current-right; } return current; } btree * min_tree(btree *root) { if(root == NULL) return root; btree * current = root; while(current-left != NULL) { current = current-left; } return current; } void binarytreetobst(btree *root) { //base-case tree is empty if(root == NULL) return; else if(root-left == NULL root-right == NULL) //base-case tree of size 1 return; else { binarytreetobst(root-left); binarytreetobst(root-right); btree* max = max_tree(root-left); if(max max-data root-data) { int temp = root-data; root-data = max-data; max-data = temp; binarytreetobst(root-left); } btree* min = min_tree(root-right); if(min min-data root-data) { int temp = root-data; root-data = min-data; min-data = temp; binarytreetobst(root-right); max = max_tree(root-left); if(max max-data root-data) { int temp = root-data; root-data = max-data; max-data = temp; binarytreetobst(root-left); } } } } On Jul 19, 8:38 am, surender sanke surend...@gmail.com wrote: @Damanshu for 1 / \ 2 3 / \ 4 5 / \ 6 7 im ending up at some non BST surender On Tue, Jul 19, 2011 at 4:06 AM, Dumanshu duman...@gmail.com wrote: @Gaurav: The best solution would be to manipulate the given BTree in place and get the BST. We don't need a separate tree but convert the existing one using the same space occupied by nodes of BT already in BST. On Jul 19, 2:06 am, Gaurav Popli gpgaurav.n...@gmail.com wrote: cant we just dotraverse using recursion and instead of printing it just pass to function which is making BST?? and is this right as someone above said first sort it and then make BST... dont we want that root of both Tree to be same or something like that...?? On Tue, Jul 19, 2011 at 2:17 AM, Dumanshu duman...@gmail.com wrote: @Balaji: for third question, were u asked to write the code? On Jul 18, 10:04 pm, Balaji S balaji.ceg...@gmail.com wrote: wats the mistake.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, 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.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Puzzle[Google] Can be Solved programatically as well
yaa.. On Tue, Jul 19, 2011 at 1:35 PM, alagammai narayanan alagamma...@gmail.comwrote: Yep.. Its German.. Were you guys able to come up with the 5 * 5 matrix... As in who lives in which house?What does he drink,smoke etc.. On Tue, Jul 19, 2011 at 1:31 PM, archita monga kool.arc...@gmail.comwrote: German! On Tue, Jul 19, 2011 at 1:22 PM, D!leep Gupta dileep.smil...@gmail.comwrote: Ans. *German* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon
The algo gives the number of set bits in the number as pointed out by SAMMM above. -- 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/-/lyzigAph1iYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] calculating permutations
HI, Is there a method to calculate something like 23!/(7!*10!) i.e. permutations with repeated elements in such a way that we need not calculate all the factorials involved? The problem in calculating all the factorials is in storing them. As 23! will make even long long in C++ to overflow, but the required answer won't. Thanks -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon
Ok then What about ques 2 ? On Tue, Jul 19, 2011 at 1:40 PM, Nitish Garg nitishgarg1...@gmail.comwrote: The algo gives the number of set bits in the number as pointed out by SAMMM above. -- 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/-/lyzigAph1iYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?
doing xor of all elements in array[][] should work. you start from a[0] [0] to a[0][n] then a[1][0] .. when the xor value bcomz 0 then the corresponding value in arr[i][j] is the first repeated element in the array. though this code will have two loops and seem as O(n2) it will terminate once it finds the first repeated no. hope my algo works. comments plz On Jul 19, 2:14 am, Dumanshu duman...@gmail.com wrote: You have to use parallel computing to find the first repeating number in O(n) time if theres nothing special about the 2-D array Use n +1 processes, n processes to scan each row and 1 process to scan the rows last and next rows first element to check for repetition. Each process uses hash table to find the first non repeating number. When we have the results from all the processes, do O(n) scanning, and output the result for minimum row which wud be the first repetition. On Jul 18, 10:42 pm, snehi jain snehijai...@gmail.com wrote: this question was asked in an interview. Regards Snehi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: calculating permutations
For this you can use pascal triangle . It will give the permutation value of the the series . 1 1 2 1 1 33 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 151 This can easily prepreocessed using dynamic method way . a[0][i]=1 1=i=n a[i][0]=1 1=i=n a[i][j] = a[i-1][j-1]+a[i][j-1] try this out -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] EXPLAIN THE OUTPUTS
#includestdio.h int * fun(int a1,int b) { int a[2]; a[0]=a1; a[1]=b; //int c=5; printf(%x\n,a[0]); return a; } int main() { int *r=fun(3,5); printf(%d\n,r[0]); printf(%d\n,r[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.
[algogeeks] INFINITY
Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Memory Allocation
char a[] or any array refers to a block of memory (not a single memory location or variable). Analogy to this can be seen in the following fact :- The memory addresses of an array can't be changed, whereas the content of the pointer variables, such as the base memory address of the array it refers to or simply any variable can be changed. Hence an undefined result persists..if we really want to return an array from a function we use the following syntax.. *char a[] = Hello; char *b = (char *)malloc(strlen(a)+1); strcpy(b,a); return b;* here we are returning the base address of the character array, unlike as wat you were doing previously(previously you were trying to return a block of memory) Hope it is clear now... :) -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] INFINITY
*printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: INFINITY
In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: INFINITY
http://chexed.com/ComputerTips/asciicodes.php On Tue, Jul 19, 2011 at 3:10 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: amazon
O(n) is possible . Will it serve the purpose or need less than that ??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: amazon
give your algo. On Tue, Jul 19, 2011 at 3:26 PM, SAMMM somnath.nit...@gmail.com wrote: O(n) is possible . Will it serve the purpose or need less than that ??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Shilpa Gupta B.Tech. 3rd year Computer Science and Engineering 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] Re: amazon
Take 2 node pointers.Move one at the speed of twice the other(first:node-next,second:node-next-next) when the first pointer reaches the end of the list,the second will give you the middle node. On Tue, Jul 19, 2011 at 3:27 PM, shilpa gupta shilpagupta...@gmail.comwrote: give your algo. On Tue, Jul 19, 2011 at 3:26 PM, SAMMM somnath.nit...@gmail.com wrote: O(n) is possible . Will it serve the purpose or need less than that ??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Shilpa Gupta B.Tech. 3rd year Computer Science and Engineering 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. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?
@Venkat. That algorithm doesnt work actually.Try for 9,8,1. At 1 , it becomes 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] Re: amazon
exactly archita. On Tue, Jul 19, 2011 at 3:33 PM, archita monga kool.arc...@gmail.comwrote: Take 2 node pointers.Move one at the speed of twice the other(first:node-next,second:node-next-next) when the first pointer reaches the end of the list,the second will give you the middle node. On Tue, Jul 19, 2011 at 3:27 PM, shilpa gupta shilpagupta...@gmail.comwrote: give your algo. On Tue, Jul 19, 2011 at 3:26 PM, SAMMM somnath.nit...@gmail.com wrote: O(n) is possible . Will it serve the purpose or need less than that ??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Shilpa Gupta B.Tech. 3rd year Computer Science and Engineering 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. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 manish.pathak*@*timesgroup.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] Re: amazon
*node *middle(node *head) { node *mid; mid = head; for(int i = 2;head!=NULL;head=head-next,i++) { (i%2==1) mid = mid-next; } return mid; }* To find 1/3rd of a list, change (i%2==1) to (i%3==1)i.e. nth node can be found (i%n==1) (make sure n=no. of nodes) Now to find 3/4th of a node, we can do following initial call *threefourth(head,3,4);* *node *threefourth(node *head,int m,int n) { node *mid,*p; p = head-next; mid = head; while(m) { for(int i = 2;p!=NULL;p=p-next,i++) { (i%n==1) mid = mid-next; } m--; if(m==0) return mid; else mid = mid-next; p = head-next; } }* -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: amazon
Ignore my previous post for find the 3/4th...its actually traversing the list thriceso it better you traverse the list once and find the number of nodes in it...then then traverse 3/4th times the number of nodes... But the algo given by me is efficient if we are required to compute 1/nth of a node... -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: amazon
Yaa this will work , you need to handle the case for odd number of nodes . For even number of node it will serve the purpose . Yaa for the second part also you can use the ratio concept fast pointer : slow pointer = 4:3 slow = ptr-next-next-next fast = ptr-next-next-next-next Here also we need to handle the case if the number of node is not a multiple of 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] Solve it
I hope it can be solved using DP...check my algo below and give any counter case if you get it... 1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] Hope the above algo works... On Tue, Jul 19, 2011 at 2:59 PM, sagar pareek sagarpar...@gmail.com wrote: Given an array all of whose elements are positive numbesr, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjecent in the array. eg:- 3 2 7 10 should return (sum of 3 and 10) 3 2 5 10 7 should returnn 15 (sum of 3,5,7) -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: amazon
take two ptrs ptr1 and ptr2 pointing to head move ptr1 until 1/4th of size of list. move ptr1 and ptr2 until ptr1=null ptr2 is pointing at 3/4th surender On Tue, Jul 19, 2011 at 3:42 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa this will work , you need to handle the case for odd number of nodes . For even number of node it will serve the purpose . Yaa for the second part also you can use the ratio concept fast pointer : slow pointer = 4:3 slow = ptr-next-next-next fast = ptr-next-next-next-next Here also we need to handle the case if the number of node is not a multiple of 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: INFINITY
yeah in my ubuntu too its not printing :) On Tue, Jul 19, 2011 at 3:20 PM, SAMMM somnath.nit...@gmail.com wrote: But if we use gcc or g++ . In that case it doesn't print it .. Wht abt tht ... On Jul 19, 2:40 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER *- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: INFINITY
Yaa guys it hav something to do with UNICODE ... I know that On Jul 19, 3:32 pm, sagar pareek sagarpar...@gmail.com wrote: yeah in my ubuntu too its not printing :) On Tue, Jul 19, 2011 at 3:20 PM, SAMMM somnath.nit...@gmail.com wrote: But if we use gcc or g++ . In that case it doesn't print it .. Wht abt tht ... On Jul 19, 2:40 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER *- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Solve it
would u please code it for me :) On Tue, Jul 19, 2011 at 3:49 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I hope it can be solved using DP...check my algo below and give any counter case if you get it... 1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] Hope the above algo works... On Tue, Jul 19, 2011 at 2:59 PM, sagar pareek sagarpar...@gmail.comwrote: Given an array all of whose elements are positive numbesr, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjecent in the array. eg:- 3 2 7 10 should return (sum of 3 and 10) 3 2 5 10 7 should returnn 15 (sum of 3,5,7) -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: amazon
Part 1: Take 2 pointers moving at different speed... 1st with head-next 2nd with head-next-next when 2nd will reach the end 1st will be pointing middle... so one result is obtained Part 2: when 1st result is obtained then start with the node pointed by 1st as it will be on 1/2th part of the list Start 2 pointers again 3rd with head-next 4th with head-next-next when 4th will reach end point then 3rd will be pointing the node present at 3/4th of the list On Tue, Jul 19, 2011 at 3:54 PM, surender sanke surend...@gmail.com wrote: take two ptrs ptr1 and ptr2 pointing to head move ptr1 until 1/4th of size of list. move ptr1 and ptr2 until ptr1=null ptr2 is pointing at 3/4th surender On Tue, Jul 19, 2011 at 3:42 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa this will work , you need to handle the case for odd number of nodes . For even number of node it will serve the purpose . Yaa for the second part also you can use the ratio concept fast pointer : slow pointer = 4:3 slow = ptr-next-next-next fast = ptr-next-next-next-next Here also we need to handle the case if the number of node is not a multiple of 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: amazon
Take two pointers ptr1 and ptr2, ptr1 should move 4 nodes at a time ptr2 should move 3 nodes at a time, thats it when the ptr1 reaches the end the ptr2 will be pointing to 3/4th, same way for m/n th node. But this works best for even number of nodes in list. For odd numbers we need to compromise like finding the middle node :) Cheers, Mani On Tue, Jul 19, 2011 at 4:20 PM, Yogesh Yadav medu...@gmail.com wrote: Part 1: Take 2 pointers moving at different speed... 1st with head-next 2nd with head-next-next when 2nd will reach the end 1st will be pointing middle... so one result is obtained Part 2: when 1st result is obtained then start with the node pointed by 1st as it will be on 1/2th part of the list Start 2 pointers again 3rd with head-next 4th with head-next-next when 4th will reach end point then 3rd will be pointing the node present at 3/4th of the list On Tue, Jul 19, 2011 at 3:54 PM, surender sanke surend...@gmail.comwrote: take two ptrs ptr1 and ptr2 pointing to head move ptr1 until 1/4th of size of list. move ptr1 and ptr2 until ptr1=null ptr2 is pointing at 3/4th surender On Tue, Jul 19, 2011 at 3:42 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa this will work , you need to handle the case for odd number of nodes . For even number of node it will serve the purpose . Yaa for the second part also you can use the ratio concept fast pointer : slow pointer = 4:3 slow = ptr-next-next-next fast = ptr-next-next-next-next Here also we need to handle the case if the number of node is not a multiple of 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Regards, Mani http://www.sanidapa.com - The music Search engine -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Solve it
Piyush sorry dude but this will not work say original array be 6 8 4 1 2 3 then ur new array be 6 8 10 10 12 13 //but original answer is 12 On Tue, Jul 19, 2011 at 3:49 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I hope it can be solved using DP...check my algo below and give any counter case if you get it... 1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] Hope the above algo works... On Tue, Jul 19, 2011 at 2:59 PM, sagar pareek sagarpar...@gmail.comwrote: Given an array all of whose elements are positive numbesr, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjecent in the array. eg:- 3 2 7 10 should return (sum of 3 and 10) 3 2 5 10 7 should returnn 15 (sum of 3,5,7) -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: amazon
ok guys.. i got it thanks to all. On Tue, Jul 19, 2011 at 4:23 PM, Manikanta Babu manikantabab...@gmail.comwrote: Take two pointers ptr1 and ptr2, ptr1 should move 4 nodes at a time ptr2 should move 3 nodes at a time, thats it when the ptr1 reaches the end the ptr2 will be pointing to 3/4th, same way for m/n th node. But this works best for even number of nodes in list. For odd numbers we need to compromise like finding the middle node :) Cheers, Mani On Tue, Jul 19, 2011 at 4:20 PM, Yogesh Yadav medu...@gmail.com wrote: Part 1: Take 2 pointers moving at different speed... 1st with head-next 2nd with head-next-next when 2nd will reach the end 1st will be pointing middle... so one result is obtained Part 2: when 1st result is obtained then start with the node pointed by 1st as it will be on 1/2th part of the list Start 2 pointers again 3rd with head-next 4th with head-next-next when 4th will reach end point then 3rd will be pointing the node present at 3/4th of the list On Tue, Jul 19, 2011 at 3:54 PM, surender sanke surend...@gmail.comwrote: take two ptrs ptr1 and ptr2 pointing to head move ptr1 until 1/4th of size of list. move ptr1 and ptr2 until ptr1=null ptr2 is pointing at 3/4th surender On Tue, Jul 19, 2011 at 3:42 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa this will work , you need to handle the case for odd number of nodes . For even number of node it will serve the purpose . Yaa for the second part also you can use the ratio concept fast pointer : slow pointer = 4:3 slow = ptr-next-next-next fast = ptr-next-next-next-next Here also we need to handle the case if the number of node is not a multiple of 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Regards, Mani http://www.sanidapa.com - The music Search engine -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Shilpa Gupta B.Tech. 3rd year Computer Science and Engineering 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] Re: amazon
@Manikanta : assume we have to find 5/60th part of node then we will take a pointer moving with 5 nodes at a time and 2nd with 60 nodes at a time... for pointer with 60 nodes at a time we have to check(head-next!=null) then (head-next-next!=null) upto 60 nodes... Don't you think coding part will become much more complicated... On Tue, Jul 19, 2011 at 4:23 PM, Manikanta Babu manikantabab...@gmail.comwrote: Take two pointers ptr1 and ptr2, ptr1 should move 4 nodes at a time ptr2 should move 3 nodes at a time, thats it when the ptr1 reaches the end the ptr2 will be pointing to 3/4th, same way for m/n th node. But this works best for even number of nodes in list. For odd numbers we need to compromise like finding the middle node :) Cheers, Mani On Tue, Jul 19, 2011 at 4:20 PM, Yogesh Yadav medu...@gmail.com wrote: Part 1: Take 2 pointers moving at different speed... 1st with head-next 2nd with head-next-next when 2nd will reach the end 1st will be pointing middle... so one result is obtained Part 2: when 1st result is obtained then start with the node pointed by 1st as it will be on 1/2th part of the list Start 2 pointers again 3rd with head-next 4th with head-next-next when 4th will reach end point then 3rd will be pointing the node present at 3/4th of the list On Tue, Jul 19, 2011 at 3:54 PM, surender sanke surend...@gmail.comwrote: take two ptrs ptr1 and ptr2 pointing to head move ptr1 until 1/4th of size of list. move ptr1 and ptr2 until ptr1=null ptr2 is pointing at 3/4th surender On Tue, Jul 19, 2011 at 3:42 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa this will work , you need to handle the case for odd number of nodes . For even number of node it will serve the purpose . Yaa for the second part also you can use the ratio concept fast pointer : slow pointer = 4:3 slow = ptr-next-next-next fast = ptr-next-next-next-next Here also we need to handle the case if the number of node is not a multiple of 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Regards, Mani http://www.sanidapa.com - The music Search engine -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Solve it
The answer to the test case you mentioned is 13 only, 6+4+3 = 13. Piyush's solution will do it. On Tue, Jul 19, 2011 at 4:30 PM, sagar pareek sagarpar...@gmail.com wrote: Piyush sorry dude but this will not work say original array be 6 8 4 1 2 3 then ur new array be 6 8 10 10 12 13 //but original answer is 12 On Tue, Jul 19, 2011 at 3:49 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I hope it can be solved using DP...check my algo below and give any counter case if you get it... 1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] Hope the above algo works... On Tue, Jul 19, 2011 at 2:59 PM, sagar pareek sagarpar...@gmail.comwrote: Given an array all of whose elements are positive numbesr, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjecent in the array. eg:- 3 2 7 10 should return (sum of 3 and 10) 3 2 5 10 7 should returnn 15 (sum of 3,5,7) -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: amazon
Well the creator of programming languages were smart enuf to give loops for that.:) On Tue, Jul 19, 2011 at 4:31 PM, Yogesh Yadav medu...@gmail.com wrote: @Manikanta : assume we have to find 5/60th part of node then we will take a pointer moving with 5 nodes at a time and 2nd with 60 nodes at a time... for pointer with 60 nodes at a time we have to check(head-next!=null) then (head-next-next!=null) upto 60 nodes... Don't you think coding part will become much more complicated... On Tue, Jul 19, 2011 at 4:23 PM, Manikanta Babu manikantabab...@gmail.com wrote: Take two pointers ptr1 and ptr2, ptr1 should move 4 nodes at a time ptr2 should move 3 nodes at a time, thats it when the ptr1 reaches the end the ptr2 will be pointing to 3/4th, same way for m/n th node. But this works best for even number of nodes in list. For odd numbers we need to compromise like finding the middle node :) Cheers, Mani On Tue, Jul 19, 2011 at 4:20 PM, Yogesh Yadav medu...@gmail.com wrote: Part 1: Take 2 pointers moving at different speed... 1st with head-next 2nd with head-next-next when 2nd will reach the end 1st will be pointing middle... so one result is obtained Part 2: when 1st result is obtained then start with the node pointed by 1st as it will be on 1/2th part of the list Start 2 pointers again 3rd with head-next 4th with head-next-next when 4th will reach end point then 3rd will be pointing the node present at 3/4th of the list On Tue, Jul 19, 2011 at 3:54 PM, surender sanke surend...@gmail.comwrote: take two ptrs ptr1 and ptr2 pointing to head move ptr1 until 1/4th of size of list. move ptr1 and ptr2 until ptr1=null ptr2 is pointing at 3/4th surender On Tue, Jul 19, 2011 at 3:42 PM, SAMMM somnath.nit...@gmail.comwrote: Yaa this will work , you need to handle the case for odd number of nodes . For even number of node it will serve the purpose . Yaa for the second part also you can use the ratio concept fast pointer : slow pointer = 4:3 slow = ptr-next-next-next fast = ptr-next-next-next-next Here also we need to handle the case if the number of node is not a multiple of 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Regards, Mani http://www.sanidapa.com - The music Search engine -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Solve it
I think 6+4+3 6+4+2 On Tue, Jul 19, 2011 at 4:30 PM, sagar pareek sagarpar...@gmail.com wrote: Piyush sorry dude but this will not work say original array be 6 8 4 1 2 3 then ur new array be 6 8 10 10 12 13 //but original answer is 12 On Tue, Jul 19, 2011 at 3:49 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I hope it can be solved using DP...check my algo below and give any counter case if you get it... 1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] Hope the above algo works... On Tue, Jul 19, 2011 at 2:59 PM, sagar pareek sagarpar...@gmail.comwrote: Given an array all of whose elements are positive numbesr, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjecent in the array. eg:- 3 2 7 10 should return (sum of 3 and 10) 3 2 5 10 7 should returnn 15 (sum of 3,5,7) -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Solve it
oh yeah my misunderstanding sorry On Tue, Jul 19, 2011 at 4:33 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I think 6+4+3 6+4+2 On Tue, Jul 19, 2011 at 4:30 PM, sagar pareek sagarpar...@gmail.comwrote: Piyush sorry dude but this will not work say original array be 6 8 4 1 2 3 then ur new array be 6 8 10 10 12 13 //but original answer is 12 On Tue, Jul 19, 2011 at 3:49 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I hope it can be solved using DP...check my algo below and give any counter case if you get it... 1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] Hope the above algo works... On Tue, Jul 19, 2011 at 2:59 PM, sagar pareek sagarpar...@gmail.comwrote: Given an array all of whose elements are positive numbesr, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjecent in the array. eg:- 3 2 7 10 should return (sum of 3 and 10) 3 2 5 10 7 should returnn 15 (sum of 3,5,7) -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Solve it
well thanks for the solution On Tue, Jul 19, 2011 at 4:34 PM, sagar pareek sagarpar...@gmail.com wrote: oh yeah my misunderstanding sorry On Tue, Jul 19, 2011 at 4:33 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I think 6+4+3 6+4+2 On Tue, Jul 19, 2011 at 4:30 PM, sagar pareek sagarpar...@gmail.comwrote: Piyush sorry dude but this will not work say original array be 6 8 4 1 2 3 then ur new array be 6 8 10 10 12 13 //but original answer is 12 On Tue, Jul 19, 2011 at 3:49 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I hope it can be solved using DP...check my algo below and give any counter case if you get it... 1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] Hope the above algo works... On Tue, Jul 19, 2011 at 2:59 PM, sagar pareek sagarpar...@gmail.comwrote: Given an array all of whose elements are positive numbesr, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjecent in the array. eg:- 3 2 7 10 should return (sum of 3 and 10) 3 2 5 10 7 should returnn 15 (sum of 3,5,7) -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Solve it
@Sagar: 13 is the correct answer. (6+4+3) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Solve it
ok ok ok thank you all On Tue, Jul 19, 2011 at 4:35 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Sagar: 13 is the correct answer. (6+4+3) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Solve it
New constraint:- What if the array also contains positive and negative numbers? On Tue, Jul 19, 2011 at 4:36 PM, sagar pareek sagarpar...@gmail.com wrote: ok ok ok thank you all On Tue, Jul 19, 2011 at 4:35 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Sagar: 13 is the correct answer. (6+4+3) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Solve it
Won't this recurrence work: s[i] = max(s[i-2], s[i-2]+a[i], a[i-1]) work? I think it works. On Tue, Jul 19, 2011 at 4:54 PM, oppilas . jatka.oppimi...@gmail.comwrote: New constraint:- What if the array also contains positive and negative numbers? On Tue, Jul 19, 2011 at 4:36 PM, sagar pareek sagarpar...@gmail.comwrote: ok ok ok thank you all On Tue, Jul 19, 2011 at 4:35 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Sagar: 13 is the correct answer. (6+4+3) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Memory Allocation
Yes, to a great extent. Thanks :) Obviously we can pass arrays across functions by declaring them static. Just saying. -- 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/-/dpYbwj0LyhcJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Solve it
Typo in my above post. s[i] = max(s[i-2], s[i-2]+a[i], s[i-1]) work? On Tue, Jul 19, 2011 at 4:59 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Won't this recurrence work: s[i] = max(s[i-2], s[i-2]+a[i], a[i-1]) work? I think it works. On Tue, Jul 19, 2011 at 4:54 PM, oppilas . jatka.oppimi...@gmail.comwrote: New constraint:- What if the array also contains positive and negative numbers? On Tue, Jul 19, 2011 at 4:36 PM, sagar pareek sagarpar...@gmail.comwrote: ok ok ok thank you all On Tue, Jul 19, 2011 at 4:35 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Sagar: 13 is the correct answer. (6+4+3) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] GETS
the gets function gives me error when i execute the following code plzz provide suggestions and answers char str[100]; while(n--) { gets(str); puts(str); } suggest alternative methods to solve the anomaly -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: GETS
You can try this :- fgets(buff,sizeof(buff),stdin) .. It is recomended not to use gets in g++ or gcc .. On Jul 19, 4:40 pm, Ankit Sablok ankitsablok19091...@gmail.com wrote: the gets function gives me error when i execute the following code plzz provide suggestions and answers char str[100]; while(n--) { gets(str); puts(str); } suggest alternative methods to solve the anomaly -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Puzzle[Google] Can be Solved programatically as well
Can you please the explain the approach.. Would be very helpful... I dint get it ... On Tue, Jul 19, 2011 at 1:37 PM, archita monga kool.arc...@gmail.comwrote: yaa.. On Tue, Jul 19, 2011 at 1:35 PM, alagammai narayanan alagamma...@gmail.com wrote: Yep.. Its German.. Were you guys able to come up with the 5 * 5 matrix... As in who lives in which house?What does he drink,smoke etc.. On Tue, Jul 19, 2011 at 1:31 PM, archita monga kool.arc...@gmail.comwrote: German! On Tue, Jul 19, 2011 at 1:22 PM, D!leep Gupta dileep.smil...@gmail.comwrote: Ans. *German* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Regards Abhishek Iyer If You Obey All the Rules, You Will Miss All the Fun. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: GETS
Y is it not recommended to use gets in g++ what is the exact reason can u tell On Jul 19, 4:47 pm, SAMMM somnath.nit...@gmail.com wrote: You can try this :- fgets(buff,sizeof(buff),stdin) .. It is recomended not to use gets in g++ or gcc .. On Jul 19, 4:40 pm, Ankit Sablok ankitsablok19091...@gmail.com wrote: the gets function gives me error when i execute the following code plzz provide suggestions and answers char str[100]; while(n--) { gets(str); puts(str); } suggest alternative methods to solve the anomaly -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: GETS
It is because it doesn't check any bound checking . So overflow can easily occur without user's concent . On Jul 19, 4:48 pm, Ankit Sablok ankitsablok19091...@gmail.com wrote: Y is it not recommended to use gets in g++ what is the exact reason can u tell On Jul 19, 4:47 pm, SAMMM somnath.nit...@gmail.com wrote: You can try this :- fgets(buff,sizeof(buff),stdin) .. It is recomended not to use gets in g++ or gcc .. On Jul 19, 4:40 pm, Ankit Sablok ankitsablok19091...@gmail.com wrote: the gets function gives me error when i execute the following code plzz provide suggestions and answers char str[100]; while(n--) { gets(str); puts(str); } suggest alternative methods to solve the anomaly- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: INFINITY
printf(\u221E\n); On Tue, Jul 19, 2011 at 4:10 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa guys it hav something to do with UNICODE ... I know that On Jul 19, 3:32 pm, sagar pareek sagarpar...@gmail.com wrote: yeah in my ubuntu too its not printing :) On Tue, Jul 19, 2011 at 3:20 PM, SAMMM somnath.nit...@gmail.com wrote: But if we use gcc or g++ . In that case it doesn't print it .. Wht abt tht ... On Jul 19, 2:40 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER *- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon
ankit solution is correct all five bases will be 1/5 and altitude of each triangle will be h same. so all have equal area. 1/2*(b/5) *h. On Tue, Jul 19, 2011 at 2:07 PM, sagar pareek sagarpar...@gmail.com wrote: Ok then What about ques 2 ? On Tue, Jul 19, 2011 at 1:40 PM, Nitish Garg nitishgarg1...@gmail.comwrote: The algo gives the number of set bits in the number as pointed out by SAMMM above. -- 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/-/lyzigAph1iYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: INFINITY
It's strange I tried it in GCC version 2.95.3 there is gives error , but in upper version it gives the correct answer . I will thinking it will be same for different version . I also gone for that , but i was having the intution that it doesn't give the right answer . Version is a serious mess. Moral of the story :-- Keep ur system upgraded . On Jul 19, 5:24 pm, varun pahwa varunpahwa2...@gmail.com wrote: printf(\u221E\n); On Tue, Jul 19, 2011 at 4:10 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa guys it hav something to do with UNICODE ... I know that On Jul 19, 3:32 pm, sagar pareek sagarpar...@gmail.com wrote: yeah in my ubuntu too its not printing :) On Tue, Jul 19, 2011 at 3:20 PM, SAMMM somnath.nit...@gmail.com wrote: But if we use gcc or g++ . In that case it doesn't print it .. Wht abt tht ... On Jul 19, 2:40 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER *- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: GETS
+1 to SAMM On Tue, Jul 19, 2011 at 5:32 PM, SAMMM somnath.nit...@gmail.com wrote: It is because it doesn't check any bound checking . So overflow can easily occur without user's concent . On Jul 19, 4:48 pm, Ankit Sablok ankitsablok19091...@gmail.com wrote: Y is it not recommended to use gets in g++ what is the exact reason can u tell On Jul 19, 4:47 pm, SAMMM somnath.nit...@gmail.com wrote: You can try this :- fgets(buff,sizeof(buff),stdin) .. It is recomended not to use gets in g++ or gcc .. On Jul 19, 4:40 pm, Ankit Sablok ankitsablok19091...@gmail.com wrote: the gets function gives me error when i execute the following code plzz provide suggestions and answers char str[100]; while(n--) { gets(str); puts(str); } suggest alternative methods to solve the anomaly- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] amazon
Calculate sum' create heap extract first k elements. On Tue, Jul 19, 2011 at 6:31 PM, Rishabh Maurya poofiefoo...@gmail.comwrote: find distances of given point P(x,y) with all other points in O(n) and build initial Max-Heap of K elements with key as distance calculated. Now compare all remaining points with the root of the heap . If its distance is less then key of root then just change the root node and its key and perform max-heapify . If not so leave the heap as it is and process next remaining point. Finally Heap will contain K elements which are closest to point P. So in short complexity is O(NLog(K)) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: INFINITY
its give me warning warning: universal character names are only valid in C++ and C99 but running... :) On Tue, Jul 19, 2011 at 6:15 PM, SAMMM somnath.nit...@gmail.com wrote: It's strange I tried it in GCC version 2.95.3 there is gives error , but in upper version it gives the correct answer . I will thinking it will be same for different version . I also gone for that , but i was having the intution that it doesn't give the right answer . Version is a serious mess. Moral of the story :-- Keep ur system upgraded . On Jul 19, 5:24 pm, varun pahwa varunpahwa2...@gmail.com wrote: printf(\u221E\n); On Tue, Jul 19, 2011 at 4:10 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa guys it hav something to do with UNICODE ... I know that On Jul 19, 3:32 pm, sagar pareek sagarpar...@gmail.com wrote: yeah in my ubuntu too its not printing :) On Tue, Jul 19, 2011 at 3:20 PM, SAMMM somnath.nit...@gmail.com wrote: But if we use gcc or g++ . In that case it doesn't print it .. Wht abt tht ... On Jul 19, 2:40 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER *- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon
Sorry for my previous post i got the solution now :) On Tue, Jul 19, 2011 at 6:29 PM, sagar pareek sagarpar...@gmail.com wrote: Yeah i saw that solution but question is to divide the traingle in 5 equals *TRIANGLES *not 5 equal parts On Tue, Jul 19, 2011 at 5:57 PM, varun pahwa varunpahwa2...@gmail.comwrote: ankit solution is correct all five bases will be 1/5 and altitude of each triangle will be h same. so all have equal area. 1/2*(b/5) *h. On Tue, Jul 19, 2011 at 2:07 PM, sagar pareek sagarpar...@gmail.comwrote: Ok then What about ques 2 ? On Tue, Jul 19, 2011 at 1:40 PM, Nitish Garg nitishgarg1...@gmail.comwrote: The algo gives the number of set bits in the number as pointed out by SAMMM above. -- 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/-/lyzigAph1iYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Puzzle and solution
Question :- Once upon a time in ancient times there was a king who was very fond of wines. He had a huge cellar, which had 1000 different varieties of wine all in different caskets (1000 caskets in all). In the adjoining kingdom there was a queen who was envious of the king’s huge wine collection. After some time when she could not bear it any more she conspired to kill her by poisoning all his wine caskets. So she one sentry to poison all the caskets, but no sooner had the sentry poisoned only one wine casket that he was caught and killed by the Royal guards. Now the king had a major problem in his hand so as to identify the right casket, which he gave to the Minister. Now the position had two peculiar qualities Anyone who takes even one drop of poison will die. But, he will die only after one month. The king also gave the Minister 10 prisoners who could be used as tasters, cause there lives was of no consequence to the king of kingdom for that matter, and the Minister was given one month to find the poisoned casket. Is it possible for the Minister to find out in one month? If so how? If not then how many months are required? My solution :- This can be done in one month Think the solution in binary ok first i wanna ask u a question :- how many bits are needed to represent the number 1000 ? yeah u r right - 10 bits so here is the solution let if any prisoner alive it mean it doesnt die and it will be represented by 1 else if he dies then he will be represented by 0 number the prisoners from 0-9 with 0 the right most (LSB) now what will be binary representation of 0 ? 00 so if 0th bottle is poisoned then all prisoners must die so taste the 0th(actually 1st) wine to all the prisoners. what is binary representation of 1? 01 so taste the 1st(actually 2nd) wine to all except the 0th prisoner. for 2nd, all except 1st (considering 0th as lowest bit) one and so on. so at the end if suppose 6th and 2nd prisoner(consider 0 min and 9 max) left alive then answer will be :- 1*2^5+1*2^1 +1 (note:- here ^= power) if anyone have more general solution pls let me know *I hope this is useful :) :)* -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: INFINITY
Dude I am using solaris with G++ version 2.95.3 . it is giving me error .. It is not compiled as a C file . it was a cpp file . It thrown as error write at the screen . On Jul 19, 6:03 pm, sagar pareek sagarpar...@gmail.com wrote: its give me warning warning: universal character names are only valid in C++ and C99 but running... :) On Tue, Jul 19, 2011 at 6:15 PM, SAMMM somnath.nit...@gmail.com wrote: It's strange I tried it in GCC version 2.95.3 there is gives error , but in upper version it gives the correct answer . I will thinking it will be same for different version . I also gone for that , but i was having the intution that it doesn't give the right answer . Version is a serious mess. Moral of the story :-- Keep ur system upgraded . On Jul 19, 5:24 pm, varun pahwa varunpahwa2...@gmail.com wrote: printf(\u221E\n); On Tue, Jul 19, 2011 at 4:10 PM, SAMMM somnath.nit...@gmail.com wrote: Yaa guys it hav something to do with UNICODE ... I know that On Jul 19, 3:32 pm, sagar pareek sagarpar...@gmail.com wrote: yeah in my ubuntu too its not printing :) On Tue, Jul 19, 2011 at 3:20 PM, SAMMM somnath.nit...@gmail.com wrote: But if we use gcc or g++ . In that case it doesn't print it .. Wht abt tht ... On Jul 19, 2:40 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: In Dev C it does On Tue, Jul 19, 2011 at 3:08 PM, SAMMM somnath.nit...@gmail.com wrote: It doesn't display the infinity symbol. On Jul 19, 2:24 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: *printf(%c\n,236);* On Tue, Jul 19, 2011 at 2:45 PM, SAMMM somnath.nit...@gmail.com wrote: Print the symbol ∞ (INFINITY) through code . Unicode .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER *- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 Official Email :: rit2008...@iiita.ac.in Another Email :: varunpahwa.ii...@gmail.com People who fail to plan are those who plan to fail.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to
Re: [algogeeks] Re: is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?
@Dumanshu: i know you have given a good explanation but i have never done parallel computing.. could you illustrate a bit more especially about the n+1th process.. On Tue, Jul 19, 2011 at 3:35 PM, Bhanu Kishore bhanukishor...@gmail.comwrote: @Venkat. That algorithm doesnt work actually.Try for 9,8,1. At 1 , it becomes 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] Re: INFINITY
# include stdio.h int main(){printf(\u221E);} Compiler details: gcc (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 -- 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/-/hrz9Qheq_XEJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?
Ya sorry abt that my algo is wrong! On Tue, Jul 19, 2011 at 3:35 PM, Bhanu Kishore bhanukishor...@gmail.comwrote: @Venkat. That algorithm doesnt work actually.Try for 9,8,1. At 1 , it becomes 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. -- Cheers, Vicky -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] how to optimally compute a matrix (nXn) to the power of k?
question had come in Amazon interview ... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: how to optimally compute a matrix (nXn) to the power of k?
This is done by using exponential theory :- I am giving my code here for a^b int power (int a,int b) { int x=1,y=a; while(b0) { if(b%2==1) x=(x*y) if (b/=2) y=(y*y); } return x; } Run time O(log b) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: c++ smart pointers
Implementation of smart pointer: template class T class *auto_ptr* { T* ptr;public: explicit *auto_ptr*(T* p = 0) : ptr(p) {} *~auto_ptr*() {delete ptr;} T *operator**() {return *ptr;} T* *operator-*() {return ptr;} // ...}; Its all there in this link: http://ootips.org/yonat/4dev/smart-pointers.html On Mon, Jul 18, 2011 at 7:45 PM, DK divyekap...@gmail.com wrote: I would suggest that you open the include files of your C++ compiler distribution and see how the auto_ptr class is implemented. It's not difficult. Here's how it's implemented in GCC. (see attachment). Just ignore all the GCC rubbish and the uglified names. -- DK http://twitter.com/divyekapoor http://www.divye.in -- 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/-/BaL5bORA0EwJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: how this output is obtained ?
@Vengadanathan: I think you should see this link http://c-faq.com/expr/seqpoints.html -- Thanks and Regards *Devansh Gupta* *B.Tech Third Year* *MNNIT, Allahabad* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: EXPLAIN THE OUTPUTS
@schrodinger y a[] value is not lost in first call.it should be lost in first call only? On Tue, Jul 19, 2011 at 8:24 PM, schrodinger 6fae1ce6347...@gmail.comwrote: First output of memory location is fine. Second output is also expected one. Third output will vary compiler to compiler and from time to time. This is because a[] is a local to fun(). First time when you call printf(%d\n,r[0]) its fine. but after executing printf() location of r is lost and hence you'll get different output is undefined. -- 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/-/gzaXX7gzytAJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Puzzle and solution
hey guys pls tell any other better solution ... On Tue, Jul 19, 2011 at 6:41 PM, sagar pareek sagarpar...@gmail.com wrote: Question :- Once upon a time in ancient times there was a king who was very fond of wines. He had a huge cellar, which had 1000 different varieties of wine all in different caskets (1000 caskets in all). In the adjoining kingdom there was a queen who was envious of the king’s huge wine collection. After some time when she could not bear it any more she conspired to kill her by poisoning all his wine caskets. So she one sentry to poison all the caskets, but no sooner had the sentry poisoned only one wine casket that he was caught and killed by the Royal guards. Now the king had a major problem in his hand so as to identify the right casket, which he gave to the Minister. Now the position had two peculiar qualities Anyone who takes even one drop of poison will die. But, he will die only after one month. The king also gave the Minister 10 prisoners who could be used as tasters, cause there lives was of no consequence to the king of kingdom for that matter, and the Minister was given one month to find the poisoned casket. Is it possible for the Minister to find out in one month? If so how? If not then how many months are required? My solution :- This can be done in one month Think the solution in binary ok first i wanna ask u a question :- how many bits are needed to represent the number 1000 ? yeah u r right - 10 bits so here is the solution let if any prisoner alive it mean it doesnt die and it will be represented by 1 else if he dies then he will be represented by 0 number the prisoners from 0-9 with 0 the right most (LSB) now what will be binary representation of 0 ? 00 so if 0th bottle is poisoned then all prisoners must die so taste the 0th(actually 1st) wine to all the prisoners. what is binary representation of 1? 01 so taste the 1st(actually 2nd) wine to all except the 0th prisoner. for 2nd, all except 1st (considering 0th as lowest bit) one and so on. so at the end if suppose 6th and 2nd prisoner(consider 0 min and 9 max) left alive then answer will be :- 1*2^5+1*2^1 +1 (note:- here ^= power) if anyone have more general solution pls let me know *I hope this is useful :) :)* -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: c++ smart pointers
Thanks all :) On Tue, Jul 19, 2011 at 8:37 PM, Deepthi Srinivasan deeps1...@gmail.comwrote: Implementation of smart pointer: template class T class *auto_ptr* { T* ptr;public: explicit *auto_ptr*(T* p = 0) : ptr(p) {} *~auto_ptr*() {delete ptr;} T *operator**() {return *ptr;} T* *operator-*() {return ptr;} // ...}; Its all there in this link: http://ootips.org/yonat/4dev/smart-pointers.html On Mon, Jul 18, 2011 at 7:45 PM, DK divyekap...@gmail.com wrote: I would suggest that you open the include files of your C++ compiler distribution and see how the auto_ptr class is implemented. It's not difficult. Here's how it's implemented in GCC. (see attachment). Just ignore all the GCC rubbish and the uglified names. -- DK http://twitter.com/divyekapoor http://www.divye.in -- 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/-/BaL5bORA0EwJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 n Luv Saurabh Badhai -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] interview questoin
Find unique string from a list of strings in one pass. -- regards, chinna. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: interview questoin
sorry. On Tue, Jul 19, 2011 at 9:07 PM, Shubham Maheshwari shubham.veloc...@gmail.com wrote: what is meant by unique string ...!! A string which occurs only once. On Tue, Jul 19, 2011 at 9:04 PM, SAMMM somnath.nit...@gmail.com wrote: There is only one unique string in the list of strings (words) ? There can be many. On Jul 19, 8:31 pm, pacific :-) pacific4...@gmail.com wrote: Find unique string from a list of strings in one pass. -- regards, chinna. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Shubham Maheshwari ShubZz O.o o.O enJoY ...!!! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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, chinna. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Circle Circle more Circles .........
Suppose N number of circle is given with their x y coordinate and radius . Now the question is to find the total area covered by the N circles .. Circles can be overlapping depending on their coordinates . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Circle Circle more Circles .........
can u pl tell wat is dis x y coordinate? are dey centre coordinates or any point on circumference of circle.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?
You can try like this #include stdio.h #include string.h #define N 3 void copy(int A[N][N],int B[N][N]) { int i,j; for(i=0;iN;i++) for(j=0;jN;j++) A[i][j]=B[i][j]; } void mul(int A[N][N],int B[N][N],int M[N][N]) { int i,j,k; for(i=0;iN;i++) for(j=0;jN;j++) { M[i][j]=0; for(k=0;kN;k++) M[i][j]+=A[i][k]*B[k][j]; } } void exp(int M[N][N],int n) { int R[N][N]; int A[N][N]; int B[N][N]; int i; memset(R,0,sizeof(R)); for(i=0;iN;i++) R[i][i]=1; while(n0) { if(n%2==1) { copy(A,R); mul(M,A,R); } n=n1; copy(A,M); copy(B,M); mul(A,B,M); } copy(M,R); } int main() { int i,j; int M[N][N]; int n; for(i=0;iN;i++) for(j=0;jN;j++) scanf(%d,M[i][j]); scanf(%d,n); exp(M,n); for(i=0;iN;i++) for(j=0;jN;j++) printf(%d%c,M[i][j],j==N-1?'\n':' '); 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] Re: how to optimally compute a matrix (nXn) to the power of k?
time complexity is (cost of multiplication)*log(n) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?
is this code running? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] interview question
Consider a c++ template funtion templateclass T T Add(T a, T b) {return a+b ;} if this function is called as T c = Add(SAM, SUNG); what will happen? What is the problem in the template declaration/ How to solve the problem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?
Yes its running fine at gcc 4.3.2 . And it might show warning in that case just change the name of the function exp(). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Circle Circle more Circles .........
See the input will be :- 6 No of circles x1 y1 R1 x2 y2 R2 x3 y3 R3 x4 y4 R4 x5 y5 R5 x6 y6 R6 Output:- Area occupied by the above circles (one line) 4 decimal points . On Jul 19, 9:01 pm, priyanka goel priya888g...@gmail.com wrote: can u pl tell wat is dis x y coordinate? are dey centre coordinates or any point on circumference of circle.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] MS
Hi, Find the kth smallest element in O(logk) given 2 sorted arrays. Merging the arrays is not allowed. I can do it in O(k).. How to do in O(logk).. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?
@Rishab Thanks .. could you explain what your are doing in the function exp().. On Tue, Jul 19, 2011 at 9:47 PM, Rishabh Maurya poofiefoo...@gmail.comwrote: Yes its running fine at gcc 4.3.2 . And it might show warning in that case just change the name of the function exp(). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] interview question
here T becomes char *.. u r trying to add two addreses here... On Tue, Jul 19, 2011 at 9:46 PM, nidhi jain nidhi.jain311...@gmail.comwrote: Consider a c++ template funtion templateclass T T Add(T a, T b) {return a+b ;} if this function is called as T c = Add(SAM, SUNG); what will happen? What is the problem in the template declaration/ How to solve the problem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Re: how to optimally compute a matrix (nXn) to the power of k?
@rishabh , thnX a lot :P Plz explain further :P On Tue, Jul 19, 2011 at 10:15 PM, snehi jain snehijai...@gmail.com wrote: @Rishab Thanks .. could you explain what your are doing in the function exp().. On Tue, Jul 19, 2011 at 9:47 PM, Rishabh Maurya poofiefoo...@gmail.comwrote: Yes its running fine at gcc 4.3.2 . And it might show warning in that case just change the name of the function exp(). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Lalit Kishore Sharma, IIIT Allahabad, 7th Sem. Contact No. - +919670057056 , +918957935169 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: how to optimally compute a matrix (nXn) to the power of k?
The logic which I have posted , it works on that principle only . Take a good look . It is the standard way fopr finding the power of a number . (a^b) You take and example for a=3 and b=4 and test it in My posted code . then you will understand wht is happening . On Jul 19, 9:45 pm, snehi jain snehijai...@gmail.com wrote: @Rishab Thanks .. could you explain what your are doing in the function exp().. On Tue, Jul 19, 2011 at 9:47 PM, Rishabh Maurya poofiefoo...@gmail.comwrote: Yes its running fine at gcc 4.3.2 . And it might show warning in that case just change the name of the function exp(). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Microsoft Interview Qn - Looping
Given the following program, MS will be printed, infinite number of times: int n = 20; int i; for (i=0; in; i--) printf(MS); Apply one of the following three operations one at a time such that MS can be printed 20 times. 1. You can add only one character into it. 2. you can delete only one character in it. 3. You can replace a character by another character. Find all possible solutions for this problem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?
Yes sure , we know if A B C are matrices of same dimension then Ax(BxC)=(AxB)xC So now what SAMM is saying i.e normal exponential of any number can be applied in case of matrix expo too and the same thing I too did but using loop without recursive fashion. I hope its clear now . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: how to optimally compute a matrix (nXn) to the power of k?
Let me explain a little more :- For example :- a^b = Can be written as (a^2)^(b/2) For n is even . [ Reason:- For b/2 in my code orn=n1; in Rishabh code ] = Can be written as a.(a^2)^(b-1/2) For n is odd [ Reason :- x=(x*y) for the odd number for getting the alone ] It works on this principle . Give it a try . In my code You just have to substitute 'a' By a matrix . That will server the purpose .. I hope you doubth wil be clear .. As said earlier work with the numbers first then you will get the logic . On Jul 19, 9:54 pm, SAMMM somnath.nit...@gmail.com wrote: The logic which I have posted , it works on that principle only . Take a good look . It is the standard way fopr finding the power of a number . (a^b) You take and example for a=3 and b=4 and test it in My posted code . then you will understand wht is happening . On Jul 19, 9:45 pm, snehi jain snehijai...@gmail.com wrote: @Rishab Thanks .. could you explain what your are doing in the function exp().. On Tue, Jul 19, 2011 at 9:47 PM, Rishabh Maurya poofiefoo...@gmail.comwrote: Yes its running fine at gcc 4.3.2 . And it might show warning in that case just change the name of the function exp(). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Microsoft Interview Qn - Looping
i know 3 solns! 1) int n = 20; int i; for (i=0; i+n; i--) printf(MS); 2) int n = 20; int i; for (i=0; in; n--) printf(MS); 3) int n = 20; int i; for (i=0; -in; i--) printf(MS); On Tue, Jul 19, 2011 at 10:27 PM, Reynald reynaldsus...@gmail.com wrote: Given the following program, MS will be printed, infinite number of times: int n = 20; int i; for (i=0; in; i--) printf(MS); Apply one of the following three operations one at a time such that MS can be printed 20 times. 1. You can add only one character into it. 2. you can delete only one character in it. 3. You can replace a character by another character. Find all possible solutions for this problem. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- radhika .. :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] MS
are the sizes of the two arrays same?? On 7/19/11, swetha rahul swetharahu...@gmail.com wrote: Hi, Find the kth smallest element in O(logk) given 2 sorted arrays. Merging the arrays is not allowed. I can do it in O(k).. How to do in O(logk).. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] MS
Arrays are not of the same size On Tue, Jul 19, 2011 at 10:41 PM, Rishabh Maurya poofiefoo...@gmail.comwrote: Its solvable using Binary Search , offcourse not in log(k) but in log(sum of size of array). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] MS ques
Given an infinite stream of bits with bits being appended at the highest significant position. Give an algorithm to say whether the number formed by sequence of bits that had been processed till then , is divisible by 3 or not ? My sol: have a variable sum...find the sum of bitswhenever u add a bit do sum+=bit value ... check whether sum%3==0. Is my solution ok?? anyother good solutions ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] MS ques
use automata theory. draw dfa for divisibility by 3.. On Tue, Jul 19, 2011 at 11:23 PM, siva viknesh sivavikne...@gmail.comwrote: Given an infinite stream of bits with bits being appended at the highest significant position. Give an algorithm to say whether the number formed by sequence of bits that had been processed till then , is divisible by 3 or not ? My sol: have a variable sum...find the sum of bitswhenever u add a bit do sum+=bit value ... check whether sum%3==0. Is my solution ok?? anyother good solutions ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- SUDHANSHU PANDEY --only fair thing in this world is a chance-- -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.