Re: [algogeeks] Re: array question

2011-08-17 Thread Sanjay Rajpal
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

2011-08-17 Thread Sanjay Rajpal
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

2011-08-17 Thread Sanjay Rajpal
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.



[algogeeks] Re: array question

2011-08-17 Thread Abhishek Yadav
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.



Re: [algogeeks] Re: array question

2011-08-17 Thread Sanjay Rajpal
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

2011-08-17 Thread sukran dhawan
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.



[algogeeks] Re: array question

2011-08-16 Thread Dave
@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.



Re: [algogeeks] Re: array question

2011-08-16 Thread saurabh singh
+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

2011-08-16 Thread Anika Jain
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

2011-08-15 Thread Nikhil Veliath
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

2011-08-15 Thread mohit verma
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

2011-08-15 Thread PramodP
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

2011-08-14 Thread Dipankar Patro
@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.



[algogeeks] Re: Array question

2011-07-26 Thread Shikhar
@piyush: Just curious, how exactly can a stack be used in this
problem?

On Jul 26, 5:00 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote:
 Sorry for the above mistakeits not O(n)

 On Tue, Jul 26, 2011 at 5:29 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote:









  Use stack

  On Tue, Jul 26, 2011 at 5:22 PM, Shikhar shikharko...@gmail.com wrote:

  Given an array of integers, for each element of the array, print the
  first number on the right side of the element which is smaller than
  it. print -1 is there is no such element.

  eg: 3,4,2,18,19,1,10

  Ans: 2,2,1,10,10,-1,-1
  O(n^2) solution is trivial.

  One solution could be:
  Insert the elements of the array in a binary search tree. The moment a
  node in the binary tree gets a left child, it is the element we are
  looking for. All the nodes in the right subtree of a node which has
  just received a left child can be assigned the value of the parents'
  left child as the first smaller element to the right.
  Thus, this solution is O(nlogn).

  Does this solution work for all possible cases of input?

  Is an O(n) solution possible?

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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
  *

 --
 *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: Array question

2011-07-26 Thread Shikhar
@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.



Re: [algogeeks] Re: Array question

2011-07-26 Thread Akshata Sharma
@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

2011-07-26 Thread Akshata Sharma
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

2011-07-26 Thread ankit sambyal
@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

2011-07-26 Thread Akshata Sharma
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

2011-07-26 Thread Piyush Sinha
@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.



[algogeeks] Re: Array Question

2011-02-22 Thread Dan
Look up the Subset Sum problem.  I think you may find that you can
put together a hybrid algorithm based on the classic method of
performing subset sum calculations.   I did something similar a few
years back.  It worked out pretty good as I recall.

Dan:-)

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: Array Question

2011-02-17 Thread Dave
In O(n^2). Sort two of the arrays, say B and C, into ascending order.
For each element in A, search forward in B and backwards in C looking
for a zero sum. Something like this, using zero-based arrays of length
n:

int i, j, k;
for( i = 0 ; i  n ; ++i )
{
j = 0;
k = n-1;
while( (j  n)  (k = 0) )
{
if( a[i] + b[j] + c[k]  0 )
j++;
else if( a[i] + b[j] + c[k]  0 )
k--;
else
return TRUE;
}
}
return FALSE;

The two sorts are O(n log n). The while loop executes at most 2n times
for each value of i. So the for loop is O(n^2).

Dave

On Feb 17, 12:08 pm, bittu shashank7andr...@gmail.com wrote:
 We have three arrays
 A=[a1,a2,...an]
 B=[b1,b2,...bn]
 C=[c1,c2,...cn]

 Write a method which takes these three arrays as input and return true
 if there is a combination [ai,bj,ck] such that ai+bj+ck = 0.

 O(n^3) solution is obvious. The questions is can we do better than
 this?

 Thanks  Regards
 Shashank Mani

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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: array question

2010-06-08 Thread Minotauraus
How will it be 12 12 5 6 6?? I can understand that the first number in
the list is place first so
it could be 12 12 6 6 5. How will it be 12 12 5 6 6?

On Jun 6, 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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: array question

2010-06-07 Thread souravsain
@Anand: Your solution will take huge space and can easily be made to
run out of memory!
If arr5[] = {12,12,6,6,635}, you will run into n^3 space complexity.
For arr[5]={12,12,6,6,390625} it will be n^6.

Sain


On Jun 7, 3:27 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.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.- 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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: array question

2010-06-07 Thread Raj N
@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

2010-06-07 Thread Dheeraj Jain
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

2010-06-07 Thread Anand
@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

2010-06-07 Thread Mayur
@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.



[algogeeks] Re: array question

2010-06-06 Thread souravsain
@sharad: Your code seems will seem to give output 12,3,4 and not
12,3,3,3,4. It semes from the original description of the problem that
you also need to keep count of frequency of occurance of items in the
map.

Secondly, you have iterated through the map and got the elemenst in
same order as you had inserted. This is specific to the map in
programing language and may not be a feature available in all
languages. Conceptually map is a dictionary of name,value pair which
enables O(1) insertion, deletion and O(1) access. Traversal in the
order of insertion may not be always available. Let me know what you
feel.

Sain

On Jun 6, 4:39 pm, sharad kumar aryansmit3...@gmail.com wrote:
 #includeiostream
 #includemap
 #includeiterator
 using namespace std;
 int main()
 {
     int arr[5]={12,3,4,3,3};
     mapint,intmp;
     int i=0;
     for(i=0;i5;++i)
     {
                     if(!(mp[arr[i]]))
                     mp[arr[i]]=i;
                     else
                     continue;
                     }
                   mapint,int::iterator it;
                   for(it=mp.begin();it!=mp.end();++it)
                   coutit-secondendl;
                   cin.sync();
                   cin.get();
                   return 0;
                   }





 On Sun, Jun 6, 2010 at 3:14 PM, divya jain sweetdivya@gmail.com wrote:
  @sharad
  while storing each element in hash by your approach u ll check if its
  already there in hash. so the complexity here will be O(n2). correct me if i
  m wrong. isnt there ny better algo..?

  On 6 June 2010 06:28, sharad kumar aryansmit3...@gmail.com wrote:

  @dhivya:keep storing the first occurance element index in hash map and
  then start insertin eleement based on index position

  On Sun, Jun 6, 2010 at 12:31 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.

  --
  yezhu malai vaasa venkataramana Govinda Govinda

   --
  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.

 --
 yezhu malai vaasa venkataramana Govinda Govinda- 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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: array question

2010-06-06 Thread divya jain
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.



[algogeeks] Re: array question

2010-06-06 Thread souravsain
@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
  .
  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.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: array question

2010-06-06 Thread Anand
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.