title: how to calculate frequency of this count algorithm statement blocks?
body: <p>So I have this count algorithm from the book Algorithms 4th edition that is used in the chapter of analysis of algorithms in which they calculate the frequency of each loop, if statement in the inner loop and from the declarations at the beguinning. </p>
  
  <p>Each part they divide it in part A,B,C,D and E.
  They said that each one has the following frequency:</p>
  
  <pre><code>E  = X (depends on input)
  D = (N^3)/6 - (N^2)/2 + N/3
  C = (N^2)/2 - N/2
  B = N
  A = 1
  </code></pre>
  
  <p>I know that all this frequencies come from partial sums, but I dont understant yer how they came to each answer, I would appreciate if someone could explain me why each frequency is like that.</p>
  
  <pre><code>public static int count(int[] a)
  {
     int N = a.length; // Part A
     int cnt = 0;  // Part A
  
     for(int i = 0; i &lt; N; i++)  //Part A
        for(int j = i+1; j &lt; N; j++) // Part B
           for(int k = j+1; k &lt; N; k++) // Part C
              if(a[i] + a[j] + a[k] == 0  // Part D
                 cnt++; // Part E
  
     return cnt;
  }
  </code></pre>