title: How to find Time Complexity of given piece of code?
body: <p>We need to find out the <strong>maximum no-adjacent subset-sum</strong> in the given array,</p>
  
  <blockquote>
    <p><strong>no-adjacent</strong>: we cannot pick adjacent elements while forming the
    maximum subset-sum.</p>
  </blockquote>
  
  <p><strong><em>For example</em></strong>:</p>
  
  <p>arr = [5, 3, 7, 14]</p>
  
  <p>Solution : [5, 14] : 19 maximum sum</p>
  
  <p><strong>Explanation</strong>:</p>
  
  <p>5 and 14 are not adjacent numbers and their sum is maximum.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>int main(){
  
     //input
     int n;
     cin&gt;&gt;n;
     vector&lt;int&gt; arr;
     while(n--){
        int x;
        cin&gt;&gt;x;
        arr.push_back(x);
     }
  
     int max_adj = INT32_MIN;
  
     for (int i = 0; i &lt; arr.size(); i++)
        max_adj = max(max_adj, maxSum(arr, i));
  
   }
  
  
  int maxSum(vector&lt;int&gt; &amp;arr, int vidx) {
  
     if (vidx &gt;= arr.size()) {
         return 0;
     }
  
     int max_ = 0;
  
     for (int i = vidx + 2; i &lt; arr.size(); i++) {
         max_ = max(max_, maxSum(arr, i));
     }
  
     return max_ + arr[vidx];
  }
  </code></pre>
  
  <p>The above approach is a <strong>brute force/naive recursive</strong> approach to solve this problem. I know there exists a better <strong>dp</strong> solution.</p>
  
  <p>But, I am just looking for a way how to find out the</p>
  
  <blockquote>
    <p>Big O time complexity</p>
  </blockquote>
  
  <p>of this recursive solution <em>mathematically</em>.</p>