1

Topic: Re: an etude or not an etude

Hello, , you wrote: the familiar girl of the junior on java filled up on interview by the following problem: and who your girlfriend, the Black woman or a cat? Possibly from it it is necessary to be repelled

2

Re: Re: an etude or not an etude

Hello, , you wrote: the familiar girl of the junior on java filled up on interview by the following problem: it is given N integer numbers. Start up for definiteness it there will be array A. Each number of an array either is more or less totals of two other numbers. That is for any X, Y and Z the following condition is false: A [X] == A [Y] + A [Z]. It is asked: for what kol-in operations we can install that the given array of numbers meets the shown requirements? We have addition operations and comparing. Addition is one operation, comparing is one operation. Storage not to select, but it is possible to read/write in an array and reading/record operations are considered as the free. In the code should be no more than three integer variables and no more than one Boolean variable. The array on an output can be spoiled and to return it in an initial state not mandatory. The acquaintance solved the task, but the answer not . Say that should be no more 2*N - 1 operations. It became interesting to me. Such impression that  right answer N^2-1 was mistaken also. Or it I am mistaken? I would understand on With ++ ))) on  such to demand the real idiocy

3

Re: Re: an etude or not an etude

It became interesting to me. Such impression that  right answer N^2-1 was mistaken also. Or it I am mistaken? Always surprised: whence people take these formulas? I not so well remember , but at me it turned out here so: n!-------- * (n-1) 2 * (n-2)!

4

Re: Re: an etude or not an etude

Hello, , you wrote: the acquaintance solved the task, but the answer not . Say that should be no more 2*N - 1 operations. It became interesting to me. Such impression that  right answer N^2-1 was mistaken also. Or it I am mistaken? I think, you are mistaken. But> on  such to demand the real idiocy I yet did not understand the correct algorithm. We assume, there are only three numbers: A1, A2, A3. Then we have three inequalities: 1) A1 == A2+A3 2) A2 == A1+A3 3) A3 == A1+A2 It turns out six operations (and N^2-1 in this case 8). I thought that if somehow to add or subtract these inequalities, it is possible to destroy any one member and to reduce number of operations to five. But when I tried all it to add/subtract, at me division into a zero turned out

5

Re: Re: an etude or not an etude

Hello, , you wrote: the familiar girl of the junior on java filled up on interview by the following problem: it is given N integer numbers. Start up for definiteness it there will be array A. Each number of an array either is more or less totals of two other numbers. That is for any X, Y and Z the following condition is false: A [X] == A [Y] + A [Z]. It is asked: for what kol-in operations we can install that the given array of numbers meets the shown requirements? We have addition operations and comparing. Addition is one operation, comparing is one operation. Storage not to select, but it is possible to read/write in an array and reading/record operations are considered as the free. In the code should be no more than three integer variables and no more than one Boolean variable. The array on an output can be spoiled and to return it in an initial state not mandatory. The acquaintance solved the task, but the answer not . Say that should be no more 2*N - 1 operations. It seems to me that for one pass the task dares only in case of the sorted array. The link to an example of the decision of the task it became interesting to me. Such impression that  right answer N^2-1 was mistaken also. Or it I am mistaken? Something can in statements of the problem is passed?

6

Re: Re: an etude or not an etude

Hello, , you wrote: the familiar girl of the junior on java filled up on interview by the following problem: On the junior on java? The strange office, whether  that? Though the problem is enough  in the sense that such problems just for exercise give to students, but on the other hand advanced enough - from the majority of juniors such abilities are not required. And generally it is a little not clear that they want from it is for  developer tasks ability to solve such tasks like as well as it is not necessary, and on the other hand, advanced foreheads well solved this task not is mandatory possesses good  skills.

7

Re: Re: an etude or not an etude

Hello, , you wrote: it is given N integer numbers. Start up for definiteness it there will be array A. Each number of an array either is more or less totals of two other numbers. That is for any X, Y and Z the following condition is false: A [X] == A [Y] + A [Z]. The task on array sorting, but artful - each number 1,5 of time more previous and if the condition is broken that the task is solved - an array not . Type 1 2 4 7 12 20 33 it is norms. For sorted 2N operations of norms, but not sorted - it is doubtful that such linear complexity of sorting is possible, and without sorting does not quit to check up a condition unless bit-by-bit operations but about the such it is not told in the task. For an example an array 32 20 4 7 12 2 1 - a horse-radish for the linear number of steps to check up what not .

8

Re: Re: an etude or not an etude

Hello, _ilya _, you wrote: __> the Task on array sorting, but artful - each number> 1,5 times more previous, 6 7 10 45

9

Re: Re: an etude or not an etude

Hello, , you wrote: it is given N integer numbers. Start up for definiteness it there will be array A. Each number of an array either is more or less totals of two other numbers. That is for any X, Y and Z the following condition is false: A [X] == A [Y] + A [Z]. Perhaps meant for everyone serial x, y, z? Whereas it is possible  to give time, all the same that foobar.

10

Re: Re: an etude or not an etude

Hello, , you wrote: it became interesting to me. Such impression that  right answer N^2-1 was mistaken also. Or it I am mistaken? I in such tasks not Copenhagen, but come to mind that the right answer (N^2-1)/2 - cyclically we check the total of pairs on equality to an element, and since and + b == b + a the amount of passes by the array end comes to naught, as at bubble sort.

11

Re: Re: an etude or not an etude

Hello, Khimik, you wrote: K> I yet did not understand the correct algorithm. K> we assume, there are only three numbers: A1, A2, A3. Then we have three inequalities: K> 1) A1 == A2+A3 K> 2) A2 == A1+A3 K> 3) A3 == A1+A2 K> It turns out six operations (and N^2-1 in this case 8). I thought that if somehow to add or subtract these inequalities, it is possible to destroy any one member and to reduce number of operations to five. But when I tried all it to add/subtract, at me division into a zero If "for any X turned out, Y and Z" it is necessary to check that and a case, when Y == Z, that is 6 more inequalities. There  itself in indications it is confused, in the beginning writes two others, then any. In my opinion, any conditions in the task explicitly does not suffice, that the order was linear instead of square.

12

Re: Re: an etude or not an etude

Hello, , you wrote: Hello, Fantasist, you wrote: F>> Hello, , you wrote:>> the familiar girl of the junior on java filled up on interview by the following problem: F>> On the junior on java? The strange office, whether  that? The office saws a navigation software and there is valid a lot of mathematics. F>> though the problem is enough  in the sense that such problems just for exercise give to students if the girl confused nothing I at all do not represent possible ways of the decision. Above on a branch assumed that the array can be sorted. But even in this case to find in it an element equal to the total of two other elements -  as. The decision "in a forehead" is trivial, but it not ." The decision not  "is other question. That is the decision of the initial task is, but they did not like its complexity of calculation. But here we already precisely do not know this requirement. If the decision with the linear dependence also exists, difficult enough to expect its finding on .

13

Re: Re: an etude or not an etude

Hello, , you wrote: it is given N integer numbers. Start up for definiteness it there will be array A. Each number of an array either is more or less totals of two other numbers. That is for any X, Y and Z the following condition is false: A [X] == A [Y] + A [Z]. It is asked: for what kol-in operations we can install that the given array of numbers meets the shown requirements? We have addition operations and comparing. Addition is one operation, comparing is one operation. Storage not to select, but it is possible to read/write in an array and reading/record operations are considered as the free. In the code should be no more than three integer variables and no more than one Boolean variable. The array on an output can be spoiled and to return it in an initial state not mandatory. The acquaintance solved the task, but the answer not . Say that should be no more 2*N - 1 operations. It became interesting to me. Such impression that  right answer N^2-1 was mistaken also. Or it I am mistaken? At me while it turns out so: for About (N*ln (N)) we sort (or for O (N) if it is possible digit-by-digit sorting), and then for O (N^2) we solve on the sorted array, exact kol-in operations did not consider. The decision as well as one more companion the Author: Voseldop Date: 22.11 12:34.

14

Re: Re: an etude or not an etude

Hello, Kodt, you wrote: And here the asymptotics becomes already much more nice. Because, than further from the left edge (to be exact, - the further from zero value), the more vigorously we start to skip on an array. Can Quite be that we receive subsquare time. Is how many much more nicely? By the way, what subsquare time means? On Wikipedia it is, but is very not clearly written. But here here still what interesting moment. If array contents - superincreasing sequence in an any way we snip off the very first ~ n*n*log (n). It is a case the worst, but also . To find not upper, but an average estimation, it is necessary  like mad. And how so it turned out, what at me for square time O (N^2) dares at any case? That is my decision more effective, than yours? Or somewhere an error? UPD: and, read your one more message, at you too as a result the square. Apprx.