i think it can be done in O(n)
for each 1, calculate no. of zeros in right
and adding all no. of zeros in right of all 1's will give no. of swaps.

correct me if i am wrong

On Sat, Jun 23, 2012 at 12:19 PM, Sourabh Singh <singhsourab...@gmail.com>wrote:

> @deepika
>
> yes, it's giving number of swaps.
> still Linear time solution would be better :-)
>
> On Fri, Jun 22, 2012 at 11:38 PM, deepikaanand <swinyanand...@gmail.com>
> wrote:
> >
> > will bubble sort give number of swaps??
> >
> > I tried the (bubble sort) code of 1,0,0,1,1,0,1 ====>swapcount = 5
> > and for the array  (0,0,1,0,1,0,1,1)====>swapcount = 3
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*DARPAN BAWEJA*
*3rd year, I.T*
*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.

Reply via email to