New answers tagged

0

Here is an easy way to answer this kind of question. Modify the function so that it counts the number of multiplications it performs. This can be done in various ways, which I'll let you figure out. Alternatively, you can write a recurrence equation for the number of multiplications. Let us denote the number of multiplications when the argument is $n$ by $M(...


0

With 0-indexed arrays, and stopping the loop at the last non-trivial random selection, we have for x = n to 2 step -1: swap A[x-1], A[uniform_random(0 inclusive to x exclusive)] vs for x = 0 to n-2 step 1: swap A[x], A[uniform_random(x inclusive to n exclusive)] which would probably be implemented as for x = 0 to n-2 step 1: swap A[x], A[x + ...


0

During the forward pass, you compute F such that F[i] represents the maximum possible profit when restricting yourself to the elements with indices 0,1..,i. During the backward pass, you compute B such that B[i] represents the maximum possible profit when restricting yourself to the elements with indices i,i+1,..,n-1 (where n is the size of your list). The ...


Top 50 recent answers are included