@deepika anand solution given by me is for getting number of swap's in O(n)
as far as sorting goes any O(n lgn) algo can be used . if count sort is allowed then O(n) for sorting also.[constant extra space.. ] On Sat, Jun 23, 2012 at 12:49 AM, ashish jain <ashishjainco...@gmail.com> wrote: > @all > > yaa.. For getting number of swaps.. we have to calculate total number of > zeroes on the right for each '1' and on adding them > we will get the number of swaps. and in O(n) time. > > > On Sat, Jun 23, 2012 at 1:16 PM, Guruprasad Sridharan > <sridharan.mi...@gmail.com> wrote: >> >> It will work because we need to swap only adjacent elements. So we do a >> sweep from left to right finding the number of ones encountered to the left >> of a zero when we find a zero. We keep adding the number as we sweep the >> entire length. >> >> >> On Sat, Jun 23, 2012 at 1:14 PM, deepikaanand <swinyanand...@gmail.com> >> wrote: >>> >>> @saurabh..wat array r u getting finally....is it all 1's or in sorted >>> order for the input >>> int a[8]={1,1,1,0,1,0,1,1}; >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from 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. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.