title: Time complexity of Search in 2D array
body: <p>In my opinion, the best case time complexity of the following code is O(1), i.e. number to be searched is found as the first element but the worst-case time complexity is O(n**2) because there can be n number of elements in each array and there can be n arrays in 2d array (nested loop to search)</p>
  <p>Please let me know if you agree/disagree.</p>
  <p>Note: below code is an example of an NxN array. My question is in general for NxN array and not specific to the following code.</p>
  <pre><code>#include &lt;iostream&gt;
  
  int M[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
  int x = 20;
  
  bool searchM(){
    for(int i=0;i&lt;3;i++)
    {
      for(int j=0;j&lt;3;j++)
      {
        if(M[i][j]==x)
        {
          return true;
        }
      }
    }
    return false;
  } 
  
  int main() {
    std::cout &lt;&lt; searchM();
  }
  </code></pre>