Re: [algogeeks] Re: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-25 Thread manoj janoti
what will happen if the values are " -6,7,5,8,3,4 " i.e if there are some of
negative values in the array

On Fri, Jun 25, 2010 at 4:42 PM, Xin  wrote:

> Do normal sorting, but when odd number take the negative value of if.
> e.g. 7,5,8,3,4 -->  -7,-5,8,-3,4
>
> --
> 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.
>
>

-- 
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: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-25 Thread Xin
Do normal sorting, but when odd number take the negative value of if.
e.g. 7,5,8,3,4 -->  -7,-5,8,-3,4

-- 
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: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-25 Thread divya jain
@ gurav vivek

i think u r only exchanging odd and even.. only putting even to end and odd
in front and not doing descending sorting on odds and ascending on even..

plz correct me if i hv missed something..

On 24 June 2010 22:49, Vivek Sundararajan  wrote:

> Hi, how about this -
>
> Do a merge sort, now, while merging two sorted list, give more priority to
> odd numbers :)
>
> I believe this falls into the right solutions :)
>
> Any breaking cases?
>
>
> On 24 June 2010 09:41, Gaurav Singh  wrote:
>
>> I think in this case, bubble sorting will be a better idea. just
>> replace the condition of comparison with the condition that earlier
>> number is even and later number is odd. I mean we can do sumthing lyk
>> this :
>>
>> for i=1 to n-1
>>  for j=1 to n-i-1
>> if iseven(ar[j]) AND (NOT iseven(ar[j+1]))
>> then   swap both of them.
>>
>> Please correct me if I am wrong somewhere.
>>
>> --
>> 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.
>>
>>
>
>
> --
> "Reduce, Reuse and Recycle"
> Regards,
> Vivek.S
>
> --
> 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.
>

-- 
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: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-24 Thread Vivek Sundararajan
Hi, how about this -

Do a merge sort, now, while merging two sorted list, give more priority to
odd numbers :)

I believe this falls into the right solutions :)

Any breaking cases?

On 24 June 2010 09:41, Gaurav Singh  wrote:

> I think in this case, bubble sorting will be a better idea. just
> replace the condition of comparison with the condition that earlier
> number is even and later number is odd. I mean we can do sumthing lyk
> this :
>
> for i=1 to n-1
>  for j=1 to n-i-1
> if iseven(ar[j]) AND (NOT iseven(ar[j+1]))
> then   swap both of them.
>
> Please correct me if I am wrong somewhere.
>
> --
> 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.
>
>


-- 
"Reduce, Reuse and Recycle"
Regards,
Vivek.S

-- 
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: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-24 Thread Gaurav Singh
I think in this case, bubble sorting will be a better idea. just
replace the condition of comparison with the condition that earlier
number is even and later number is odd. I mean we can do sumthing lyk
this :

for i=1 to n-1
  for j=1 to n-i-1
 if iseven(ar[j]) AND (NOT iseven(ar[j+1]))
 then   swap both of them.

Please correct me if I am wrong somewhere.

-- 
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: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-24 Thread Bhanu Pratap Singh
Hi Jagadish,

Anurag's algo has O(n) for pre-processing. After that any sorting algorithm
will be applied there also.

On Wed, Jun 23, 2010 at 7:22 PM, Jagadish M  wrote:

> >Why not just change the definition of when one number is bigger than
> another
> >and do normal sort ?
> >I guess that is better and simpler.
>
> Normal sort takes O(n log n), while Anurag's algo is O(n).
>
>
> Regards,
> Jagadish
> http://www.cse.iitb.ac.in/~jagadish
>
>
>
>
>
>
> On Jun 20, 2:18 pm, Rohit Saraf  wrote:
> > Why not just change the definition of when one number is bigger than
> another
> > and do normal sort ?
> > I guess that is better and simpler.
> > --
> > Rohit Saraf
> > Second Year Undergraduate,
> > Dept. of Computer Science and Engineering
> > IIT 
> > Bombayhttp://www.cse.iitb.ac.in/~rohitfeb14
> >
> > On Sun, Jun 20, 2010 at 7:52 AM, Anurag Sharma  >wrote:
> >
> >
> >
> > > Keep 2 pointers 'start' and 'end' and make them point to start and
> > > beginning of the array.
> >
> > > Now keep decresing *end* pointer until an odd element is found
> > > Keep increasing the *start* pointer until an even element is found
> > > swap the elements at start and end
> > > Continue the above 3 steps till start >
> > > Now the start/end points to a border element which divides the array in
> 2
> > > parts, 1st have having all odd numbers and 2nd half with all even
> numbers.
> >
> > > Now use any inplace sorting algorithm to sort in descending order the
> > > portion containing all odd numbers and in increasing order the portion
> > > containing all  even numbers.
> > > Hope its clear.
> >
> > > Anurag Sharma
> >
> > > On Sun, Jun 20, 2010 at 2:15 AM, vijay  wrote:
> >
> > >>  There is an array of odd and even numbers. Now, sort them in such a
> > >> way that the top portion of the array contains odd numbers, bottom
> > >> portion contains even numbers. The odd numbers are to be sorted in
> > >> descending order and the even numbers in ascending order. You are not
> > >> allowed to use any extra array and it has to use a conventional
> > >> sorting mechanism and should not do any pre or post processing
> >
> > >> --
> > >> 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.
> >
> > >  --
> > > 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.
>
> --
> 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.
>
>


-- 
Regards
Bhanu
Mobile   +91 9886738496

-- 
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: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-23 Thread Dave
No, Jagadish. You missed the statement "Now use any inplace sorting
algorithm" in Anurag's posting, which makes his algorithm also O(n log
n), and both Anurag and you missed the statement "should not do any
pre or post processing."

Dave

On Jun 23, 8:52 am, Jagadish M  wrote:
> >Why not just change the definition of when one number is bigger than another
> >and do normal sort ?
> >I guess that is better and simpler.
>
> Normal sort takes O(n log n), while Anurag's algo is O(n).
>
> Regards,
> Jagadishhttp://www.cse.iitb.ac.in/~jagadish
>
> On Jun 20, 2:18 pm, Rohit Saraf  wrote:
>
>
>
> > Why not just change the definition of when one number is bigger than another
> > and do normal sort ?
> > I guess that is better and simpler.
> > --
> > Rohit Saraf
> > Second Year Undergraduate,
> > Dept. of Computer Science and Engineering
> > IIT Bombayhttp://www.cse.iitb.ac.in/~rohitfeb14
>
> > On Sun, Jun 20, 2010 at 7:52 AM, Anurag Sharma 
> > wrote:
>
> > > Keep 2 pointers 'start' and 'end' and make them point to start and
> > > beginning of the array.
>
> > > Now keep decresing *end* pointer until an odd element is found
> > > Keep increasing the *start* pointer until an even element is found
> > > swap the elements at start and end
> > > Continue the above 3 steps till start
> > > Now the start/end points to a border element which divides the array in 2
> > > parts, 1st have having all odd numbers and 2nd half with all even numbers.
>
> > > Now use any inplace sorting algorithm to sort in descending order the
> > > portion containing all odd numbers and in increasing order the portion
> > > containing all  even numbers.
> > > Hope its clear.
>
> > > Anurag Sharma
>
> > > On Sun, Jun 20, 2010 at 2:15 AM, vijay  wrote:
>
> > >>  There is an array of odd and even numbers. Now, sort them in such a
> > >> way that the top portion of the array contains odd numbers, bottom
> > >> portion contains even numbers. The odd numbers are to be sorted in
> > >> descending order and the even numbers in ascending order. You are not
> > >> allowed to use any extra array and it has to use a conventional
> > >> sorting mechanism and should not do any pre or post processing
>
> > >> --
> > >> 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 > >>  .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 > >  .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.



[algogeeks] Re: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers

2010-06-23 Thread Jagadish M
>Why not just change the definition of when one number is bigger than another
>and do normal sort ?
>I guess that is better and simpler.

Normal sort takes O(n log n), while Anurag's algo is O(n).


Regards,
Jagadish
http://www.cse.iitb.ac.in/~jagadish






On Jun 20, 2:18 pm, Rohit Saraf  wrote:
> Why not just change the definition of when one number is bigger than another
> and do normal sort ?
> I guess that is better and simpler.
> --
> Rohit Saraf
> Second Year Undergraduate,
> Dept. of Computer Science and Engineering
> IIT Bombayhttp://www.cse.iitb.ac.in/~rohitfeb14
>
> On Sun, Jun 20, 2010 at 7:52 AM, Anurag Sharma wrote:
>
>
>
> > Keep 2 pointers 'start' and 'end' and make them point to start and
> > beginning of the array.
>
> > Now keep decresing *end* pointer until an odd element is found
> > Keep increasing the *start* pointer until an even element is found
> > swap the elements at start and end
> > Continue the above 3 steps till start
> > Now the start/end points to a border element which divides the array in 2
> > parts, 1st have having all odd numbers and 2nd half with all even numbers.
>
> > Now use any inplace sorting algorithm to sort in descending order the
> > portion containing all odd numbers and in increasing order the portion
> > containing all  even numbers.
> > Hope its clear.
>
> > Anurag Sharma
>
> > On Sun, Jun 20, 2010 at 2:15 AM, vijay  wrote:
>
> >>  There is an array of odd and even numbers. Now, sort them in such a
> >> way that the top portion of the array contains odd numbers, bottom
> >> portion contains even numbers. The odd numbers are to be sorted in
> >> descending order and the even numbers in ascending order. You are not
> >> allowed to use any extra array and it has to use a conventional
> >> sorting mechanism and should not do any pre or post processing
>
> >> --
> >> 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 >>  .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 > .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.