Re: [algogeeks] Odd Even Sort array

2011-06-05 Thread Apoorve Mohan
int j=1; for(i=2;i wrote: > Hi all, > > Sort all elements in odd indices of an array in ascending order and > even indices in descending order. > Finally, rearrange so that all even indexed elements come first. > > eg: > > input – 7 2 6 4 8 3 1 > > even indexed : 7 6 8 1 => sort 8 7 6 1 > odd inde

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread Logic King
@ross i can do it in O(n) time using an extra array of the same size as the given array first sort both the even indexed terms and odd indexed terms by modifying quick sort...it can be done in one traversal. and then using extra array and then move the even indexed terms followed by odd index

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread saurabh singh
Yup...I think thats the way to go...modify heap sort...'ignoring the odd childs' for ascending and ignoring the even child for decending. If i am wrong in this then quick sort has to be the solution. On Sat, May 28, 2011 at 8:44 AM, subramania jeeva wrote: > I hope merge sort is not an inplace so

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread subramania jeeva
I hope merge sort is not an inplace sorting.. It'll take extra space (in function merge) and since it uses recursion it'll also take stack space.. I think this sol will work. 1. partition the array by holding the even elements on first space(n/2 or n/2-1 depends on odd sized and even sized array)

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread Piyush Sinha
how large n will be...O(n) can't grow more than O(nlogn)so in any case the complexity is going to be O(nlogn)..so i dnt see any point of bringing our any modification of mergersort...even if u think so, provide a concrete algo On 5/28/11, LALIT SHARMA wrote: > It will give correct answer , >

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread LALIT SHARMA
It will give correct answer , but instead of doing manipulation after taking input. as it would take some O(n) time. if n would be large , we would incur this extra cost . we should change the termination condition of merge-sort function and modify the merge function of merge sort ..to reach our o

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread Piyush Sinha
main() { int a[100]; int i,j,N; printf("enter the number of elements: "); scanf("%d",&N); for(i=0;i wrote: > wat about insertion sort (with some limited conditions obviously ) ?? > > On Sat, May 28, 2011 at 12:56 AM, Piyush Sinha > wrote: > >> will it be given th

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread srajan dongre
wat about insertion sort (with some limited conditions obviously ) ?? On Sat, May 28, 2011 at 12:56 AM, Piyush Sinha wrote: > will it be given that the number of elements is always even?? > > On 5/28/11, ross wrote: > > Hi all, > > > > Sort all elements in odd indices of an array in ascending o

Re: [algogeeks] Odd Even Sort array

2011-05-27 Thread Piyush Sinha
will it be given that the number of elements is always even?? On 5/28/11, ross wrote: > Hi all, > > Sort all elements in odd indices of an array in ascending order and > even indices in descending order. > Finally, rearrange so that all even indexed elements come first. > > eg: > > input – 7 2 6

[algogeeks] Odd Even Sort array

2011-05-27 Thread ross
Hi all, Sort all elements in odd indices of an array in ascending order and even indices in descending order. Finally, rearrange so that all even indexed elements come first. eg: input – 7 2 6 4 8 3 1 even indexed : 7 6 8 1 => sort 8 7 6 1 odd indexed: 2 4 3 => sort 2 3 4 output – 8 7 6 1 2 3