But Vaibhav's solution I think is O(n^2). For example, when input is

101 102 103 104 1 2 3 4

We first swap 1 and 101 and then bubble 101 to the end of the subarray 2 3 4
.

This bubbling we must repeat after each swap.

This results in n/2 + n/2-1 + n/2-2 + .. comparisons, which is O(n^2).

Please correct me if I am wrong.

Can this be solved in better than O(n^2) with constant space ?

Thanks,
Balaji.

On Tue, Apr 12, 2011 at 8:43 PM, Carl Barton <[email protected]>wrote:

> That's linear space, not constant space.
> Vaibhav's seems good for constant space solution
>
>
> On 12 April 2011 13:17, sravanreddy001 <[email protected]> wrote:
>
>> Yes.. merge sort.
>>
>> O(n) to find the starting of 2nd sub-array.
>> and O(n) for the merge process (similar to last step in merge sort)
>>
>> O(n)
>>
>> On Apr 12, 2:37 pm, Akash Agrawal <[email protected]> wrote:
>> > Given an array with two subparts sorted. How will you make a final
>> sorted
>> > array.
>> >
>> > i/p:  1, 5, 7, 9, 11, 23, 2, 3, 8, 9, 21
>> >
>> > o/p:
>> > 1, 2, 3, 5, 7, 8, 9, 9, 11, 21, 23
>> >
>> > Regards,
>> > Akash Agrawalhttp://tech-queries.blogspot.com/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to