### Is there a system behind the magic of algorithm analysis?

There are lots of questions about how to analyze the running time of algorithms (see, e.g., runtime-analysis and algorithm-analysis). Many are similar, for instance those asking for a cost analysis of nested loops or divide & conquer algorithms, but most answers seem to be tailor-made.On the other hand, the answers to another general question explain the larger picture (in particular regarding asymptotic analysis) with some examples, but not how to get your hands dirty.Is there a structured, general method for analysing the cost of algorit...Read more

### runtime analysis - Triple nested for-loops

Possible Duplicate: A puzzle related to nested loops I am trying to count the exact/total number of iterations the following nested for-loops are executed:s=0for (i: 1 to n) for (j: 1 to i) for (k: j to i) s = s + 1I know that the first two for-loops will have n(n+1)/2 iterations. My problem is with the third for-loop. Due to this third loop what factor am I supposed to multiply with n(n+1)/2 to get the total number of iterations? Any help would be appreciated? Thanks...Read more

### runtime analysis - Logarithmic run time for calculating prime numbers?

Here's the function I'm currently analyzing. I know it's not the most optimal but I'm not understanding the $\theta()$ of this algorithm. I've been told that it's not actually $\theta(n)$ but instead a logarithmic run-time and it had something to do with the bits of the value passed in. I'm not understanding how the bits are causing the logarithmic so if someone can explain that it'd be great. function isPrime(n):1 if n = 2 return true2 for i from 2 to n3 if n % i = 0 return false4 return true...Read more

### runtime analysis - Calculate execution time from linear speedup

Given an execution time $t(c_1)$ and linear speedup $s$, how do you calculate the execution time for $c_2$ processor cores?(Assuming Gustafson's law, or in other words, $t(\infty)=0$)My ideas:I haven't found any references that give formulas for calculating execution time, surprisingly. However, I think you can derive a formula from the speedup equation:$$speedup = t(1)/t(c)$$The problem is, I'm pretty sure this is not what people are referring to when they give you a "linear speedup" factor $s$. I haven't been able to find any exact definition...Read more

### runtime analysis - Running time based on smallest subtree

I've constructed an algorithm on (rooted) binary trees, where the running time at a node depends on the size of its smaller subtree, where we compute from each leaf upwards towards the root.More specifically, at each node, a constant amount of time is required for each node in the smallest of its 2 subtrees.The running time for a tree with $n$ nodes is then easily bounded by $O(n^2)$, however, I conjecture that the running time is bounded by $O(n \log n)$, since I think $\sum_{x\in V(T)}\min(|V_l(x)|, |V_r(x)|) \leq O(n \log n)$ holds.How would...Read more

### average case - Is this a correct approch of finding expected runtime of an algorithm?

Consider two algorithms; we analysis their run time only by counting the number of comparisonsTwoMax1(A): S = negative infinite L = negative infinite loop through the array A if A[i] > L: S = L L = A[i] else if A[i] > S S = A[i] return (L,S) TwoMax2(A): S = negative infinite L = negative infinite loop through the array A if A[i] > S: if A[i] > L: S = L L = A[i] else S...Read more