mockers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

FIND ELEMENTS: Bansal Sir

3 posters

Go down

FIND ELEMENTS: Bansal Sir Empty FIND ELEMENTS: Bansal Sir

Post  ballu Sun Feb 01, 2009 9:29 pm

let there be n elements
a1,a2,....,an
given an array with n*(n-1)/2 elements like this
a1+a2,a1+a3,a1+a4,..a1+an, a2+a3,a2+a4,a2+a5,...,a2+an,............................,aN-1,aN
In O(n)time and no extra space find the elements a1,..,aN
ballu
ballu

Posts : 58
Join date : 2009-02-01

Back to top Go down

FIND ELEMENTS: Bansal Sir Empty Re: FIND ELEMENTS: Bansal Sir

Post  mnnit.rahul Tue Feb 03, 2009 6:01 pm

in first iteration,
find sum of all numbers, so sum is n*(a1+a2----an) divide no by n so we get s=(a1+a2+a3+............an)

then traverse again after n step we get (a*n+(a2+a3+.....an)) = (n-1)a1 + s so we can calculate a1
similarly after next n-1 we get (n-1)*n2+(s-n2-n1) as we know a1 and s we can calculate a2
similarly we can calculate other values
complexity=o(2n)



am i right??????????

mnnit.rahul

Posts : 51
Join date : 2009-02-01

Back to top Go down

FIND ELEMENTS: Bansal Sir Empty @Ballu

Post  Admin Wed Feb 04, 2009 10:50 am

is it that the elements are given in order??
if then rahul etawah has solved it.

Admin
Admin

Posts : 47
Join date : 2009-01-29

https://mockers.forumotion.com

Back to top Go down

FIND ELEMENTS: Bansal Sir Empty @Etawah

Post  ballu Fri Feb 06, 2009 9:29 pm

OVERFLOW
ab karo
ballu
ballu

Posts : 58
Join date : 2009-02-01

Back to top Go down

FIND ELEMENTS: Bansal Sir Empty Re: FIND ELEMENTS: Bansal Sir

Post  mnnit.rahul Fri Feb 06, 2009 10:35 pm

3rd last element =An-2 + An-1
2nd last element = An-1 + An
subtracting these we get An - An-1
now last element = An + An-1
now using these two we can obtain An and An-1

similarly we can find other values

mnnit.rahul

Posts : 51
Join date : 2009-02-01

Back to top Go down

FIND ELEMENTS: Bansal Sir Empty @etawah

Post  ballu Sat Feb 07, 2009 2:12 am

abhi bhi overflow
ballu
ballu

Posts : 58
Join date : 2009-02-01

Back to top Go down

FIND ELEMENTS: Bansal Sir Empty Re: FIND ELEMENTS: Bansal Sir

Post  mnnit.rahul Sat Feb 07, 2009 11:24 am

ab to 2 no ko subtract kar raha hoon ab kyu hoga overflow

mnnit.rahul

Posts : 51
Join date : 2009-02-01

Back to top Go down

FIND ELEMENTS: Bansal Sir Empty Re: FIND ELEMENTS: Bansal Sir

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum