title: Calculate time and space complexity of a program to remove duplicate entries
body: <p><strong>What</strong> </p>
  
  <p>I have written a small piece of code to find and remove if any duplicate number in an integer array. I have made use of List for this. </p>
  
  <p><strong>The Code</strong></p>
  
  <pre><code>    static int[] RemoveDuplicate(int[] input)
      {
         List&lt;int&gt; correctedList = new List&lt;int&gt;();
  
         for(int i = 0; i &lt; input.Length; i++)
         {
             if (!correctedList.Contains(input[i]))
             {
                 correctedList.Add(input[i]);
             }
             else
             {
                 //skip
             }
         }
  
         return correctedList.ToArray();
  
      }
  </code></pre>
  
  <p><strong>My Difficulty</strong></p>
  
  <p>I need to know how to find time complexity for this small piece of code written, and if possible how to optimize it.</p>
  
  <p><strong>What have I tried</strong></p>
  
  <p>I have done some reading on the Internet about how to calculate time and space complexity of an algorithm, and below is what I feel is the answer, but since I am new to this I thought rather than going with a wrong assumption it would be better to consult some experts on this.</p>
  
  <p><strong>Below is what I tried.</strong></p>
  
  <p>List correctedList = new List(); --> This will be executed 1 time</p>
  
  <p>int i =0; -->This will be executed 1 time</p>
  
  <p>int i &lt; input.Length --> This will be executed N times</p>
  
  <p>i++ --> This will be executed N times</p>
  
  <p>if (!correctedList.Contains(input[i])) --> This may be executed N times</p>
  
  <p>correctedList.Add(input[i]); --> This may be executed N times</p>
  
  <p>So, the total number of operations = 1 + 1 + N + N + N + N = 4N+2</p>
  
  <p><strong>Is this equal to  O(N) ?</strong></p>
  
  <p>and is my method of calculating time complexity correct ?</p>
  
  <p>Thank in advance </p>