Re: [algogeeks] Re: array question
See when u xor two same numbers, the result is 0. So as mentioned in the question, all numbers occur twice, so the result will be 0 for them and the one occuring once will be left(as 0 ^ number gives number itself). Hope u got Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India Contact: +91-8053566286, +91-9729683720 On Tue, Aug 16, 2011 at 10:07 PM, Anika Jain anika.jai...@gmail.com wrote: i cudnt understand how is it done here by using xor by chen.. aftergetting F it wud be the xor of of odd occuring elements, fine, then he wrote if(xor)A1 ==0 how is this logic used?? On Wed, Aug 17, 2011 at 8:17 AM, saurabh singh saurab...@gmail.comwrote: +1 to dave.xor is the way to go. On Tue, Aug 16, 2011 at 7:06 PM, Dave dave_and_da...@juno.com wrote: @Raghavan: But aren't maps implemented as binary search trees? That would make insertion and searching O(log n), and the overall operation O(n log n). Dave On Aug 16, 4:08 am, Raghavan its...@gmail.com wrote: @sukran: If you were asking for the map based solution space and time complexity would be o(n). On Tue, Aug 16, 2011 at 2:34 PM, sukran dhawan sukrandha...@gmail.com wrote: what is the complexity in which it has been done ? On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote: Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards, Raghavan KL -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: array question
Oh sorry, i didnt read the question carefully:) Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India On Wed, Aug 17, 2011 at 12:34 AM, Sanjay Rajpal sanjay.raj...@live.inwrote: See when u xor two same numbers, the result is 0. So as mentioned in the question, all numbers occur twice, so the result will be 0 for them and the one occuring once will be left(as 0 ^ number gives number itself). Hope u got Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India Contact: +91-8053566286, +91-9729683720 On Tue, Aug 16, 2011 at 10:07 PM, Anika Jain anika.jai...@gmail.comwrote: i cudnt understand how is it done here by using xor by chen.. aftergetting F it wud be the xor of of odd occuring elements, fine, then he wrote if(xor)A1 ==0 how is this logic used?? On Wed, Aug 17, 2011 at 8:17 AM, saurabh singh saurab...@gmail.comwrote: +1 to dave.xor is the way to go. On Tue, Aug 16, 2011 at 7:06 PM, Dave dave_and_da...@juno.com wrote: @Raghavan: But aren't maps implemented as binary search trees? That would make insertion and searching O(log n), and the overall operation O(n log n). Dave On Aug 16, 4:08 am, Raghavan its...@gmail.com wrote: @sukran: If you were asking for the map based solution space and time complexity would be o(n). On Tue, Aug 16, 2011 at 2:34 PM, sukran dhawan sukrandha...@gmail.comwrote: what is the complexity in which it has been done ? On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote: Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards, Raghavan KL -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: array question
See when u xor two same numbers, the result is 0. So as mentioned in the question, all numbers occur twice, so the result will be 0 for them and the one occuring once will be left(as 0 ^ number gives number itself). Hope u got it :) Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India On Tue, Aug 16, 2011 at 10:07 PM, Anika Jain anika.jai...@gmail.com wrote: i cudnt understand how is it done here by using xor by chen.. aftergetting F it wud be the xor of of odd occuring elements, fine, then he wrote if(xor)A1 ==0 how is this logic used?? On Wed, Aug 17, 2011 at 8:17 AM, saurabh singh saurab...@gmail.comwrote: +1 to dave.xor is the way to go. On Tue, Aug 16, 2011 at 7:06 PM, Dave dave_and_da...@juno.com wrote: @Raghavan: But aren't maps implemented as binary search trees? That would make insertion and searching O(log n), and the overall operation O(n log n). Dave On Aug 16, 4:08 am, Raghavan its...@gmail.com wrote: @sukran: If you were asking for the map based solution space and time complexity would be o(n). On Tue, Aug 16, 2011 at 2:34 PM, sukran dhawan sukrandha...@gmail.com wrote: what is the complexity in which it has been done ? On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote: Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards, Raghavan KL -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: array question
Yes, sry abhishek , i didnt see the question carefully. But this can be done with hash map requiring O(n) space and O(n) time. Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India On Wed, Aug 17, 2011 at 2:15 AM, Abhishek Yadav abhishek30.nit...@gmail.com wrote: Thats right...by doing xor this can't be done...hey sanjay please reconsider your answer. On Aug 17, 2:05 pm, sukran dhawan sukrandha...@gmail.com wrote: when u xor nos with odd number of times we will get back the same no.only even occurences will give 0.question is to find the no with even occurence.how will you find that no? On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote: Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You wreceived this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: array question
pl give the algo On Wed, Aug 17, 2011 at 2:50 PM, Sanjay Rajpal srn...@gmail.com wrote: Yes, sry abhishek , i didnt see the question carefully. But this can be done with hash map requiring O(n) space and O(n) time. Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India On Wed, Aug 17, 2011 at 2:15 AM, Abhishek Yadav abhishek30.nit...@gmail.com wrote: Thats right...by doing xor this can't be done...hey sanjay please reconsider your answer. On Aug 17, 2:05 pm, sukran dhawan sukrandha...@gmail.com wrote: when u xor nos with odd number of times we will get back the same no.only even occurences will give 0.question is to find the no with even occurence.how will you find that no? On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote: Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You wreceived this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: array question
+1 to dave.xor is the way to go. On Tue, Aug 16, 2011 at 7:06 PM, Dave dave_and_da...@juno.com wrote: @Raghavan: But aren't maps implemented as binary search trees? That would make insertion and searching O(log n), and the overall operation O(n log n). Dave On Aug 16, 4:08 am, Raghavan its...@gmail.com wrote: @sukran: If you were asking for the map based solution space and time complexity would be o(n). On Tue, Aug 16, 2011 at 2:34 PM, sukran dhawan sukrandha...@gmail.com wrote: what is the complexity in which it has been done ? On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote: Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards, Raghavan KL -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: array question
i cudnt understand how is it done here by using xor by chen.. aftergetting F it wud be the xor of of odd occuring elements, fine, then he wrote if(xor)A1 ==0 how is this logic used?? On Wed, Aug 17, 2011 at 8:17 AM, saurabh singh saurab...@gmail.com wrote: +1 to dave.xor is the way to go. On Tue, Aug 16, 2011 at 7:06 PM, Dave dave_and_da...@juno.com wrote: @Raghavan: But aren't maps implemented as binary search trees? That would make insertion and searching O(log n), and the overall operation O(n log n). Dave On Aug 16, 4:08 am, Raghavan its...@gmail.com wrote: @sukran: If you were asking for the map based solution space and time complexity would be o(n). On Tue, Aug 16, 2011 at 2:34 PM, sukran dhawan sukrandha...@gmail.com wrote: what is the complexity in which it has been done ? On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote: Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards, Raghavan KL -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Fwd: Re: [algogeeks] Re: array question
Dave tu mahan hai . . . . -- Forwarded message -- From: Dipankar Patro dip10c...@gmail.com Date: 14 Aug 2011 23:27 Subject: Re: [algogeeks] Re: array question To: algogeeks@googlegroups.com @Dave nice algo. Really like it. So the whole complexity depends on the sorting. On 14 August 2011 22:58, Dave dave_and_da...@juno.com wrote: @Dipankar: If extra space is not allowed, I think the optimal solution is to sort the two arrays, which takes O(max(m log m, n log n)). Then the common element can be found in O(m + n) by a simple search that starts at i = j = 0 and increments the index of the lesser of a[i] and b[j]. Overall complexity is O(max(m log m, n log n)). Dave On Aug 14, 8:24 am, Dipankar Patro dip10c...@gmail.com wrote: @ Sagar: What if extra space in not allowed? I think then we have to use the binary search method... On 14 August 2011 18:50, sagar pareek sagarpar...@gmail.com wrote: Hashing O(n+m) On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro dip10c...@gmail.com wrote: how about binary search of each element from array 1 on array 2? overall complexity : O(nlogn) On 14 August 2011 18:46, mohit verma mohit89m...@gmail.com wrote: example: array 1 :: 1 2 3 4 5 6 7 8 9 10 15 array 2:: 23 34 56 13 15 57 432 348 On Sun, Aug 14, 2011 at 6:44 PM, shady sinv...@gmail.com wrote: meaning ? what is a common element ? example ??? On Sun, Aug 14, 2011 at 6:37 PM, mohit verma mohit89m...@gmail.com wrote: given two arrays : with all distinct elements but one element in common. Find the common element in optimal time. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http
Re: Re: [algogeeks] Re: array question
thanks guys. On Mon, Aug 15, 2011 at 1:12 PM, Nikhil Veliath nve...@gmail.com wrote: Dave tu mahan hai . . . . -- Forwarded message -- From: Dipankar Patro dip10c...@gmail.com Date: 14 Aug 2011 23:27 Subject: Re: [algogeeks] Re: array question To: algogeeks@googlegroups.com @Dave nice algo. Really like it. So the whole complexity depends on the sorting. On 14 August 2011 22:58, Dave dave_and_da...@juno.com wrote: @Dipankar: If extra space is not allowed, I think the optimal solution is to sort the two arrays, which takes O(max(m log m, n log n)). Then the common element can be found in O(m + n) by a simple search that starts at i = j = 0 and increments the index of the lesser of a[i] and b[j]. Overall complexity is O(max(m log m, n log n)). Dave On Aug 14, 8:24 am, Dipankar Patro dip10c...@gmail.com wrote: @ Sagar: What if extra space in not allowed? I think then we have to use the binary search method... On 14 August 2011 18:50, sagar pareek sagarpar...@gmail.com wrote: Hashing O(n+m) On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro dip10c...@gmail.com wrote: how about binary search of each element from array 1 on array 2? overall complexity : O(nlogn) On 14 August 2011 18:46, mohit verma mohit89m...@gmail.com wrote: example: array 1 :: 1 2 3 4 5 6 7 8 9 10 15 array 2:: 23 34 56 13 15 57 432 348 On Sun, Aug 14, 2011 at 6:44 PM, shady sinv...@gmail.com wrote: meaning ? what is a common element ? example ??? On Sun, Aug 14, 2011 at 6:37 PM, mohit verma mohit89m...@gmail.comwrote: given two arrays : with all distinct elements but one element in common. Find the common element in optimal time. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group
Re: Re: [algogeeks] Re: array question
Step 1: Sort the smaller array mlogm Step 2: For every element in the bigger array, do a binary search on this sorted smaller array. n*logm Total complexity (m+n)logm You could sort the other array and binary search from the smaller array but then it would be (m+n)logn which is bigger than (m+n)logm On Mon, Aug 15, 2011 at 7:18 PM, mohit verma mohit89m...@gmail.com wrote: thanks guys. On Mon, Aug 15, 2011 at 1:12 PM, Nikhil Veliath nve...@gmail.com wrote: Dave tu mahan hai . . . . -- Forwarded message -- From: Dipankar Patro dip10c...@gmail.com Date: 14 Aug 2011 23:27 Subject: Re: [algogeeks] Re: array question To: algogeeks@googlegroups.com @Dave nice algo. Really like it. So the whole complexity depends on the sorting. On 14 August 2011 22:58, Dave dave_and_da...@juno.com wrote: @Dipankar: If extra space is not allowed, I think the optimal solution is to sort the two arrays, which takes O(max(m log m, n log n)). Then the common element can be found in O(m + n) by a simple search that starts at i = j = 0 and increments the index of the lesser of a[i] and b[j]. Overall complexity is O(max(m log m, n log n)). Dave On Aug 14, 8:24 am, Dipankar Patro dip10c...@gmail.com wrote: @ Sagar: What if extra space in not allowed? I think then we have to use the binary search method... On 14 August 2011 18:50, sagar pareek sagarpar...@gmail.com wrote: Hashing O(n+m) On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro dip10c...@gmail.com wrote: how about binary search of each element from array 1 on array 2? overall complexity : O(nlogn) On 14 August 2011 18:46, mohit verma mohit89m...@gmail.com wrote: example: array 1 :: 1 2 3 4 5 6 7 8 9 10 15 array 2:: 23 34 56 13 15 57 432 348 On Sun, Aug 14, 2011 at 6:44 PM, shady sinv...@gmail.com wrote: meaning ? what is a common element ? example ??? On Sun, Aug 14, 2011 at 6:37 PM, mohit verma mohit89m...@gmail.comwrote: given two arrays : with all distinct elements but one element in common. Find the common element in optimal time. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: array question
@Dave nice algo. Really like it. So the whole complexity depends on the sorting. On 14 August 2011 22:58, Dave dave_and_da...@juno.com wrote: @Dipankar: If extra space is not allowed, I think the optimal solution is to sort the two arrays, which takes O(max(m log m, n log n)). Then the common element can be found in O(m + n) by a simple search that starts at i = j = 0 and increments the index of the lesser of a[i] and b[j]. Overall complexity is O(max(m log m, n log n)). Dave On Aug 14, 8:24 am, Dipankar Patro dip10c...@gmail.com wrote: @ Sagar: What if extra space in not allowed? I think then we have to use the binary search method... On 14 August 2011 18:50, sagar pareek sagarpar...@gmail.com wrote: Hashing O(n+m) On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro dip10c...@gmail.com wrote: how about binary search of each element from array 1 on array 2? overall complexity : O(nlogn) On 14 August 2011 18:46, mohit verma mohit89m...@gmail.com wrote: example: array 1 :: 1 2 3 4 5 6 7 8 9 10 15 array 2:: 23 34 56 13 15 57 432 348 On Sun, Aug 14, 2011 at 6:44 PM, shady sinv...@gmail.com wrote: meaning ? what is a common element ? example ??? On Sun, Aug 14, 2011 at 6:37 PM, mohit verma mohit89m...@gmail.com wrote: given two arrays : with all distinct elements but one element in common. Find the common element in optimal time. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- *MOHIT VERMA* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] an array question
1.scan the array and find the maximum digits of integer. lets say m.. 2.Again scan the array and pad the intergers whose digits are less that m ( m) with zero's .. copy the new integers in a new array 3.sort the new array in desc order and carry the same even for original array. 4. Now the original array contains the required output. ex: original aarray 23,8,19,9,1 max digits : 2 (for 23 as well as 19) step 2: new array 23,80,19,90,10 step3. sort .. 90,80,23,19,10 .. and corresponding original is .. 98231910. original array contains the original output.. On Sat, Aug 13, 2011 at 7:15 AM, chengjie qi starboy...@gmail.com wrote: int compare(int a, int b) { string s = Integer.tostring(a); string y = Integer.tostring(b); if (s +y y+s) return -1; else return 1; } use this to write quick sort , you can get the answer. On Fri, Aug 12, 2011 at 8:34 PM, Yasir Imteyaz yasir@gmail.comwrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] an array question
@$ did not understand how the original array is sorted to give the number! On Sat, Aug 13, 2011 at 12:50 PM, *$* gopi.komand...@gmail.com wrote: 1.scan the array and find the maximum digits of integer. lets say m.. 2.Again scan the array and pad the intergers whose digits are less that m ( m) with zero's .. copy the new integers in a new array 3.sort the new array in desc order and carry the same even for original array. 4. Now the original array contains the required output. ex: original aarray 23,8,19,9,1 max digits : 2 (for 23 as well as 19) step 2: new array 23,80,19,90,10 step3. sort .. 90,80,23,19,10 .. and corresponding original is .. 98231910. original array contains the original output.. On Sat, Aug 13, 2011 at 7:15 AM, chengjie qi starboy...@gmail.com wrote: int compare(int a, int b) { string s = Integer.tostring(a); string y = Integer.tostring(b); if (s +y y+s) return -1; else return 1; } use this to write quick sort , you can get the answer. On Fri, Aug 12, 2011 at 8:34 PM, Yasir Imteyaz yasir@gmail.com wrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
@$ the ans should be 9823191 and not 98231910 On Sat, Aug 13, 2011 at 12:59 PM, Nikhil Veliath nve...@gmail.com wrote: @$ did not understand how the original array is sorted to give the number! On Sat, Aug 13, 2011 at 12:50 PM, *$* gopi.komand...@gmail.com wrote: 1.scan the array and find the maximum digits of integer. lets say m.. 2.Again scan the array and pad the intergers whose digits are less that m ( m) with zero's .. copy the new integers in a new array 3.sort the new array in desc order and carry the same even for original array. 4. Now the original array contains the required output. ex: original aarray 23,8,19,9,1 max digits : 2 (for 23 as well as 19) step 2: new array 23,80,19,90,10 step3. sort .. 90,80,23,19,10 .. and corresponding original is .. 98231910. original array contains the original output.. On Sat, Aug 13, 2011 at 7:15 AM, chengjie qi starboy...@gmail.com wrote: int compare(int a, int b) { string s = Integer.tostring(a); string y = Integer.tostring(b); if (s +y y+s) return -1; else return 1; } use this to write quick sort , you can get the answer. On Fri, Aug 12, 2011 at 8:34 PM, Yasir Imteyaz yasir@gmail.com wrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
hi nikhil.. correct ... just type error.. but as per my algo .. as we need to consider the elements of original array... the last element is 1 , but not 10. On Sat, Aug 13, 2011 at 1:01 PM, Nikhil Veliath nve...@gmail.com wrote: @$ the ans should be 9823191 and not 98231910 On Sat, Aug 13, 2011 at 12:59 PM, Nikhil Veliath nve...@gmail.com wrote: @$ did not understand how the original array is sorted to give the number! On Sat, Aug 13, 2011 at 12:50 PM, *$* gopi.komand...@gmail.com wrote: 1.scan the array and find the maximum digits of integer. lets say m.. 2.Again scan the array and pad the intergers whose digits are less that m ( m) with zero's .. copy the new integers in a new array 3.sort the new array in desc order and carry the same even for original array. 4. Now the original array contains the required output. ex: original aarray 23,8,19,9,1 max digits : 2 (for 23 as well as 19) step 2: new array 23,80,19,90,10 step3. sort .. 90,80,23,19,10 .. and corresponding original is .. 98231910. original array contains the original output.. On Sat, Aug 13, 2011 at 7:15 AM, chengjie qi starboy...@gmail.com wrote: int compare(int a, int b) { string s = Integer.tostring(a); string y = Integer.tostring(b); if (s +y y+s) return -1; else return 1; } use this to write quick sort , you can get the answer. On Fri, Aug 12, 2011 at 8:34 PM, Yasir Imteyaz yasir@gmail.com wrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] an array question
import java.util.Arrays; import java.util.Comparator; public class NewSort implements ComparatorInteger { @Override public int compare(Integer o1, Integer o2) { String s1 = o1.toString(); String s2 = o2.toString(); String com1 = s1 + s2; String com2 = s2 + s1; if (com1.compareTo(com2) 0 ) { return 1; } else if (com1.compareTo(com2) == 0) { return 0; } else { return -1; } } public static void main(String[] args) { Integer[] a = new Integer[5]; a[0] = 23; a[1] = 8; a[2] = 19; a[3] = 9; a[4] = 1; Arrays.sort(a, new NewSort()); for (int i = 0; i 5; i++) { System.out.print(a[i]); } System.out.println(); } } On Sat, Aug 13, 2011 at 3:39 PM, *$* gopi.komand...@gmail.com wrote: hi nikhil.. correct ... just type error.. but as per my algo .. as we need to consider the elements of original array... the last element is 1 , but not 10. On Sat, Aug 13, 2011 at 1:01 PM, Nikhil Veliath nve...@gmail.com wrote: @$ the ans should be 9823191 and not 98231910 On Sat, Aug 13, 2011 at 12:59 PM, Nikhil Veliath nve...@gmail.com wrote: @$ did not understand how the original array is sorted to give the number! On Sat, Aug 13, 2011 at 12:50 PM, *$* gopi.komand...@gmail.com wrote: 1.scan the array and find the maximum digits of integer. lets say m.. 2.Again scan the array and pad the intergers whose digits are less that m ( m) with zero's .. copy the new integers in a new array 3.sort the new array in desc order and carry the same even for original array. 4. Now the original array contains the required output. ex: original aarray 23,8,19,9,1 max digits : 2 (for 23 as well as 19) step 2: new array 23,80,19,90,10 step3. sort .. 90,80,23,19,10 .. and corresponding original is .. 98231910. original array contains the original output.. On Sat, Aug 13, 2011 at 7:15 AM, chengjie qi starboy...@gmail.com wrote: int compare(int a, int b) { string s = Integer.tostring(a); string y = Integer.tostring(b); if (s +y y+s) return -1; else return 1; } use this to write quick sort , you can get the answer. On Fri, Aug 12, 2011 at 8:34 PM, Yasir Imteyaz yasir@gmail.com wrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] an array question
we will sort the new array in desc order .. and we will carry the same order even to original array.. so after sorting the new arraay will be 90,80,23,19,10 .. so corresponding original array is 9823191 On Sat, Aug 13, 2011 at 12:50 PM, *$* gopi.komand...@gmail.com wrote: 1.scan the array and find the maximum digits of integer. lets say m.. 2.Again scan the array and pad the intergers whose digits are less that m ( m) with zero's .. copy the new integers in a new array 3.sort the new array in desc order and carry the same even for original array. 4. Now the original array contains the required output. ex: original aarray 23,8,19,9,1 max digits : 2 (for 23 as well as 19) step 2: new array 23,80,19,90,10 step3. sort .. 90,80,23,19,10 .. and corresponding original is .. 98231910. original array contains the original output.. On Sat, Aug 13, 2011 at 7:15 AM, chengjie qi starboy...@gmail.com wrote: int compare(int a, int b) { string s = Integer.tostring(a); string y = Integer.tostring(b); if (s +y y+s) return -1; else return 1; } use this to write quick sort , you can get the answer. On Fri, Aug 12, 2011 at 8:34 PM, Yasir Imteyaz yasir@gmail.comwrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thx, --Gopi -- Thx, --Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] an array question
1 Sort the Array 2 Put it to the String Accordingly.. Prem On Fri, Aug 12, 2011 at 6:04 PM, Yasir Imteyaz yasir@gmail.com wrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
Kindly check it with both the examples. It won't work. -- 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/-/VlT1DNH-vPkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] an array question
radix sort the digits wrong way (left most digit first), and then concatenate On Fri, Aug 12, 2011 at 6:12 PM, Yasir yasir@gmail.com wrote: Kindly check it with both the examples. It won't work. -- 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/-/VlT1DNH-vPkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
Amazing , Kindly Follow me up :- 1 Given Array of Random Value ... say int a[]= {20,365,299,50,67,21}; Apply Any Sorting Algo on it... which Results into somewhat like a={365,299,67,50,21,20,.. blah..}... 2 Well No U hv to put those values to a string variable. Please lemme knw if I need more clarification.. This is simple where is the messy part?? On Fri, Aug 12, 2011 at 6:16 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: radix sort the digits wrong way (left most digit first), and then concatenate On Fri, Aug 12, 2011 at 6:12 PM, Yasir yasir@gmail.com wrote: Kindly check it with both the examples. It won't work. -- 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/-/VlT1DNH-vPkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
see the second example...if a single digit is there...tht will be at the very end of the array...and if it is 9 it must come at first place...there it goes wrong... On Fri, Aug 12, 2011 at 6:23 PM, Prem Krishna Chettri hprem...@gmail.comwrote: Amazing , Kindly Follow me up :- 1 Given Array of Random Value ... say int a[]= {20,365,299,50,67,21}; Apply Any Sorting Algo on it... which Results into somewhat like a={365,299,67,50,21,20,.. blah..}... 2 Well No U hv to put those values to a string variable. Please lemme knw if I need more clarification.. This is simple where is the messy part?? On Fri, Aug 12, 2011 at 6:16 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: radix sort the digits wrong way (left most digit first), and then concatenate On Fri, Aug 12, 2011 at 6:12 PM, Yasir yasir@gmail.com wrote: Kindly check it with both the examples. It won't work. -- 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/-/VlT1DNH-vPkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Abhishek Gupta BITS, Pilani -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] an array question
use something like radix sort, but from numbers left to right. in given example: 87 36 52 87 36 52 place 87 then 52 than 36 if input is something like 9 87 36 52 place 9875236 this you can do with minor modification of radix sort. thanks Rajesh On Fri, Aug 12, 2011 at 6:31 PM, Abhishek Gupta guptaabhishe...@gmail.com wrote: see the second example...if a single digit is there...tht will be at the very end of the array...and if it is 9 it must come at first place...there it goes wrong... On Fri, Aug 12, 2011 at 6:23 PM, Prem Krishna Chettri hprem...@gmail.com wrote: Amazing , Kindly Follow me up :- 1 Given Array of Random Value ... say int a[]= {20,365,299,50,67,21}; Apply Any Sorting Algo on it... which Results into somewhat like a={365,299,67,50,21,20,.. blah..}... 2 Well No U hv to put those values to a string variable. Please lemme knw if I need more clarification.. This is simple where is the messy part?? On Fri, Aug 12, 2011 at 6:16 PM, Nitin Nizhawan nitin.nizha...@gmail.com wrote: radix sort the digits wrong way (left most digit first), and then concatenate On Fri, Aug 12, 2011 at 6:12 PM, Yasir yasir@gmail.com wrote: Kindly check it with both the examples. It won't work. -- 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/-/VlT1DNH-vPkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Abhishek Gupta BITS, Pilani -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
I have use bactracking http://codepad.org/rF4Sr3zk it works for only 1 and 2digit number On Fri, Aug 12, 2011 at 6:04 PM, Yasir Imteyaz yasir@gmail.com wrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
I think tis works On Fri, Aug 12, 2011 at 6:16 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: radix sort the digits wrong way (left most digit first), and then concatenate On Fri, Aug 12, 2011 at 6:12 PM, Yasir yasir@gmail.com wrote: Kindly check it with both the examples. It won't work. -- 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/-/VlT1DNH-vPkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] an array question
int compare(int a, int b) { string s = Integer.tostring(a); string y = Integer.tostring(b); if (s +y y+s) return -1; else return 1; } use this to write quick sort , you can get the answer. On Fri, Aug 12, 2011 at 8:34 PM, Yasir Imteyaz yasir@gmail.com wrote: An array of integers is given and you have to find the largest possible integer by concatenating all elements: example: array: 87 36 52 answer: 875236 array: 87 9 52 answer: 98752 -- 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/-/_lJJOlRG_ukJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- stay hungry stay foolish Chengjie Qi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Array question
@Piyush, using stack i guess it can be done in O(n) On Tue, Jul 26, 2011 at 5:42 PM, Shikhar shikharko...@gmail.com wrote: @ankit: you are right...sorry about the error On Jul 26, 5:11 pm, ankit sambyal ankitsamb...@gmail.com wrote: The O/P of ur example should be 2,2,1,1,1,-1,-1 or am I getting it wrong ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Array question
a crude algo, for(i=end to start) { while(!stk.empty()) { if(arr[i]arr[stk.top]) pop(); else break; } if(!stk.empty()) l = arr.length-1; else l = stk.top; output[i]=l-i-1; stk.puch(i); } This will be O(n). Correct me I am wrong anywhere.. On Tue, Jul 26, 2011 at 5:49 PM, Akshata Sharma akshatasharm...@gmail.comwrote: @Piyush, using stack i guess it can be done in O(n) On Tue, Jul 26, 2011 at 5:42 PM, Shikhar shikharko...@gmail.com wrote: @ankit: you are right...sorry about the error On Jul 26, 5:11 pm, ankit sambyal ankitsamb...@gmail.com wrote: The O/P of ur example should be 2,2,1,1,1,-1,-1 or am I getting it wrong ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Array question
@Akshata : Plz explain ur algo... Its not clear. Like in the first iteration, else l = stk.top; is getting executed. but stack is empty, so how r u assigning value to l -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Array question
sorry for the typo ankit, its if(stk.empty()) l = arr.length-1; else l = stk.top; On Tue, Jul 26, 2011 at 6:19 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Akshata : Plz explain ur algo... Its not clear. Like in the first iteration, else l = stk.top; is getting executed. but stack is empty, so how r u assigning value to l -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Array question
@Shikhar 1) Push the first element to stack. 2) for i = 1 to n-1 a) temp =a[i] b) while(stack not empty) int x = pop(stack) if(xtemp) print(temp); else push(x,stack) break; c) push(temp,stack) 3) After the loop in step 2 is over, pop all the elements from stack and print -1 as next element for them. -- *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: array question
@Anand :Your approach will turn out very crude if elements are something like 1000, 2000 keeping an array i.e count[1000] is not feasible. I think souravsain's approach is better. On Mon, Jun 7, 2010 at 3:57 AM, Anand anandut2...@gmail.com wrote: Here is my approch which runs in O(n). http://codepad.org/d3pzYQtW http://codepad.org/d3pzYQtW On Sun, Jun 6, 2010 at 7:47 AM, divya jain sweetdivya@gmail.comwrote: output willl be 12 12 5 6 6 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote: @divya: Does your problem require the output to be sorted also? What will be the output required if inout is 12,5,6,12,6? Will it be 12,12,6,6,5 or 12,12,5,6,6,? Sain On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote: Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. So cant use a dictionary -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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: array question
The link http://geeksforgeeks.org/?p=1488 has many different solutions and implementation of hashing method. On Mon, Jun 7, 2010 at 12:59 AM, Raj N rajn...@gmail.com wrote: @Anand :Your approach will turn out very crude if elements are something like 1000, 2000 keeping an array i.e count[1000] is not feasible. I think souravsain's approach is better. On Mon, Jun 7, 2010 at 3:57 AM, Anand anandut2...@gmail.com wrote: Here is my approch which runs in O(n). http://codepad.org/d3pzYQtW http://codepad.org/d3pzYQtW On Sun, Jun 6, 2010 at 7:47 AM, divya jain sweetdivya@gmail.comwrote: output willl be 12 12 5 6 6 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote: @divya: Does your problem require the output to be sorted also? What will be the output required if inout is 12,5,6,12,6? Will it be 12,12,6,6,5 or 12,12,5,6,6,? Sain On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote: Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. So cant use a dictionary -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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: array question
@souravsain :Your approach works really well.. Here is the Implementation: http://codepad.org/ricAcQtu On Sun, Jun 6, 2010 at 11:40 AM, souravsain souravs...@gmail.com wrote: @divya:go through the elements and keep inserting them in a BST. While inserting if elements already exists in BST, increase its frequency (Node of BST has element a nd frequency). Also if elemengs is newly inserted then also place it in a seperate array. So this array (say Array M) will become something like 12,5,6. This array will give order of first occurance of numbers. This whole process will take nlogn (BST creation assuming worst case that all elements are uinque in the input array). Once done, scan through each element in array M, find its corrosponding element in BST (logn) which will give the frequency. Fill those many indexes in input array with array M[i]. If all elements are uinque, this will also take nlogn. Else if input array has m distince elements, which will require us to look into BST for m times. hence entire process has time compelxity: O(nlogn + nlogn)= O(2nlogn) Space complexity: O(2n) [1 for BST and 1 for array M, worst case when all elements are unique in inpur array). Let me know your comments if any or any better appraoch as this once may have improvements. On Jun 6, 7:47 pm, divya jain sweetdivya@gmail.com wrote: output willl be 12 12 5 6 6 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote: @divya: Does your problem require the output to be sorted also? What will be the output required if inout is 12,5,6,12,6? Will it be 12,12,6,6,5 or 12,12,5,6,6,? Sain On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote: Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. So cant use a dictionary -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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: array question
@Anand Depending upon the sequence of data in the input, an insertion/search into the (unbalanced) BST will take O(n) time causing the overall complexity to shoot up to O(n^2) for each element counted once. Sourav's approach requires a balanced binary search tree. @Divya.. If you know something about the numbers, one could do better. For example, if you knew that they're all positive short integers, Anand's original approach (of using an array indexed by the numbers themselves) will be great (for a storage cost of about 64KB). This is sometimes more acceptable, for example, if your original input is like a million integers. On Tue, Jun 8, 2010 at 5:48 AM, Anand anandut2...@gmail.com wrote: @souravsain :Your approach works really well.. Here is the Implementation: http://codepad.org/ricAcQtu On Sun, Jun 6, 2010 at 11:40 AM, souravsain souravs...@gmail.com wrote: @divya:go through the elements and keep inserting them in a BST. While inserting if elements already exists in BST, increase its frequency (Node of BST has element a nd frequency). Also if elemengs is newly inserted then also place it in a seperate array. So this array (say Array M) will become something like 12,5,6. This array will give order of first occurance of numbers. This whole process will take nlogn (BST creation assuming worst case that all elements are uinque in the input array). Once done, scan through each element in array M, find its corrosponding element in BST (logn) which will give the frequency. Fill those many indexes in input array with array M[i]. If all elements are uinque, this will also take nlogn. Else if input array has m distince elements, which will require us to look into BST for m times. hence entire process has time compelxity: O(nlogn + nlogn)= O(2nlogn) Space complexity: O(2n) [1 for BST and 1 for array M, worst case when all elements are unique in inpur array). Let me know your comments if any or any better appraoch as this once may have improvements. On Jun 6, 7:47 pm, divya jain sweetdivya@gmail.com wrote: output willl be 12 12 5 6 6 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote: @divya: Does your problem require the output to be sorted also? What will be the output required if inout is 12,5,6,12,6? Will it be 12,12,6,6,5 or 12,12,5,6,6,? Sain On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote: Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. So cant use a dictionary -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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: array question
output willl be 12 12 5 6 6 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote: @divya: Does your problem require the output to be sorted also? What will be the output required if inout is 12,5,6,12,6? Will it be 12,12,6,6,5 or 12,12,5,6,6,? Sain On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote: Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. So cant use a dictionary -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from 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: array question
Here is my approch which runs in O(n). http://codepad.org/d3pzYQtW http://codepad.org/d3pzYQtW On Sun, Jun 6, 2010 at 7:47 AM, divya jain sweetdivya@gmail.com wrote: output willl be 12 12 5 6 6 On 6 June 2010 18:27, souravsain souravs...@gmail.com wrote: @divya: Does your problem require the output to be sorted also? What will be the output required if inout is 12,5,6,12,6? Will it be 12,12,6,6,5 or 12,12,5,6,6,? Sain On Jun 6, 12:01 am, divya sweetdivya@gmail.com wrote: Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. So cant use a dictionary -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.