title: What is time complexity of 4 nested loops which each depend on the parent loop
body: <p>I'm preparing for a technical interview, and I have a problem with calculating the time complexity of my algorithm.
  I know the time complexity for two loops nested in one another is  O(n^2)
  but what if the nested loop continues the parent loop. Something like this:</p>
  
  <pre><code>for i in range(n):
    for j in range(i+1,n):
      for k in range(j+1,n):
        for q in range(k+1,n):
          print("Hello")
  </code></pre>
  
  <p>Is the time complexity for this code n^4, or something else? I wrote a program to count each operation, and I came up with 2^n, but I have no clue how to get to 2^n from 4 nested loops.</p>
  
  <p>I would appreciate if you explain your solution.</p>
  
  <p>Here is the program that I wrote to count the number of operations:</p>
  
  <pre><code>def count_operations(n):
      number_of_operations = 1
      for i in range(n):
          number_of_operations += 1
          for j in range(i + 1, n):
              number_of_operations += 1
              for k in range(j + 1, n):
                  number_of_operations += 1
                  for q in range(k + 1, n):
                      number_of_operations += 1
      print(number_of_operations)
  
  
  count_operations(1)
  count_operations(2)
  count_operations(3)
  count_operations(4)
  count_operations(5)
  count_operations(6)
  count_operations(7)
  count_operations(8)
  </code></pre>
  
  <p>output</p>
  
  <pre><code>n: 1 , number of operations: 2
  n: 2 , number of operations: 4
  n: 3 , number of operations: 8
  n: 4 , number of operations: 16
  n: 5 , number of operations: 31
  n: 6 , number of operations: 57
  n: 7 , number of operations: 99
  n: 8 , number of operations: 163
  </code></pre>