algorithm,math,time-complexity,computer-science,recurrence-relation

Here are a few hints : define R(n) = T(n)/(n-1)! solve the recurrence for R(n) express T(n) as a function of R(n) ...

c++,algorithm,recursion,recurrence-relation

The swap is irrelevant. It affects what is printed, but doesn't affect the run-time of the algorithm. So let's look at what happens: The call doSomething(arr, j, j) prints j things. The call doSomething(arr, i, j) makes j-i calls to doSomething(arr, i+1, j). Let's redefine the variables a bit and...

math,recurrence,recurrence-relation

You're right that if sqrt is the ceiling of the square root, then you'll never reach 1 by repeatedly applying square roots. I'm going to assume that you meant to use the floor, which means that you will indeed eventually hit 1 as the recurrence unwinds. In this case, your...

python,recursion,recurrence,recurrence-relation

Instead of trying to simplify this function mathematically, I simplified the algorithm in Python. As suggested by @LambdaFairy, I implemented memoization in the getNumberOfZombits(time) function. This optimization sped up the function a lot. Then, I passed to the next step, of trying to see what was the input to that...

javascript,math,recurrence-relation

Such question can always be asked to Wolfram Alpha: For price(n): Question: f(0) = 10, f(n) = f(n-1) + f(n-1) * 0.01 Answer: f(n) = 10^(1-2n) 101^n For cost(n): Question: g(n) =10^(1-2n) 101^n, f(0) = 0, f(n) = f(n-1) + g(n-1) Answer: f(n) = 10^(3-2n) 101^n - 1000 Translated to...

algorithm,recurrence,recurrence-relation

For case (ii) we are finding a subset of {x1,..,xj} that uses xj and sums to i. However, we are making this sum by combining xj with a subset of {x1,..,x(j-1)}. If we had p(i-xj,j) then we would be saying that we can make a total of i by using...

haskell,monads,moving-average,state-monad,recurrence-relation

Updated answer... Define: combine :: [ a -> State s a ] -> a -> State [s] a combine fs a = state $ \ys -> let zs = zipWith (\f y a -> runState (f a) y) fs ys pairs = chain a zs as' = map fst pairs...

dynamic-programming,recurrence,recurrence-relation

I don't really understand your recurrence relation: Let dp[i][j][k] represent sum up to i with j elements and k coins. I think you're on the right track, but I suggest simply dropping the middle dimension [j], and use dp[sum][coinsLeft] as follows: dp[0][0] = 1 // coins: 0, desired sum: 0...

dynamic-programming,recurrence-relation,subset-sum

You are almost correct ( not sure why you used min ). But let dp[i][j] store the answer of whether a subset of arr[0],arr[1],....arr[j] (here arr[] is the array of elements ) can sum upto i. That is dp[i][j] is 1 if answer is yes and 0 if answer is...

algorithm,big-o,analysis,recurrence-relation,big-theta

A recurrence relation is a way of recursively defining a function. For example, the recurrence relation T(n) = 4T(n / 3) + O(1) says that the function is defined so that if you want to determine T(n), you can evaluate T(n / 3), multiply it by 4, an add in...

algorithm,math,big-o,recurrence,recurrence-relation

Your claim that lg n * lg n = Θ(n) is false. Notice that the limit of (lg n)2 / n tends toward 0 as n goes to infinity. You can see this using l'Hopital's rule: limn → ∞ (lg n)2 / n = lim n → ∞ 2 lg...

Well, it's obviously possible for all pairs of distinct indices to be inversions (if the entire array is in reverse order, e.g.: [5,4,3,2,1]). And it's obviously not possible for more than all pairs of distinct indices to be inversions. So the question is: how many pairs of distinct indices are...

sorting,recursion,recurrence-relation,quickselect,median-of-medians

Best attempt: That equation is only for when you do the median of groups of 5. Otherwise it will change. The an part of the equation is the time it takes for the algorithm to go through all the elements and group them into 5. The T(n/5) is the time...

math,recurrence,recurrence-relation

First, we choose n = 2: T(n = 2) = (2^2 + 2 + 18) / 8 = 24 / 8 = 3 Great, that works. Now we know that there is a number k >= 2 that fulfills the definition of T(n). Then, let's set n = k+1 for...

The trick is to keep expanding until you see the pattern. T(n) = 9 T(n/3) + n^2 = 9(9T(n/3^2) + n^2/3^2) + n^2 = 9^2 T(n/3^2) + 2n^2 = 9^2 (9 T(n/3^3) + n^2/3^4) + 2n^2 = 9^3 T(n/3^3) + 3n^2 = ... = 9^k T(n/3^k) + kn^2 This keeps...

time-complexity,recurrence-relation

T(1) = O(1) T(n) = T(n-1) + O(1) This is indeed the signature of a sequential search and it has O(n) time complexity. This is because T(n) = T(n-1) has O(n) complexity and the O(1) term drops out. The solution is trivial: Say we know T(n) = T(n-1), and we...