title: Linked List time complexity for its operations
body: <p>I am implementing a Linked list in terms of stock market program.</p>
  
  <p>It has and operation -  Buy</p>
  
  <p>For Buy the code is </p>
  
  <pre><code>//Stocks is a linked List like so 
  //LinkedList&lt;Integer&gt; stocks = new LinkedList&lt;Integer&gt;();
  public void buy(int q, int p) {
      stocks.addLast(q); //add number of stocks
      stocks.addLast(p); //for i stocks i +1 = price of stock
  }
  </code></pre>
  
  <p>This operation addLast is for a Linked list obvious adds the given element to a new position at the end of a current list. </p>
  
  <p>So for example if I have a list that has lets say the following data</p>
  
  <pre><code>//Stock, price, stock, price etc...
  [100, 50, 5000, 30, 8000, 60]
  </code></pre>
  
  <p>If I <code>addLast</code> is the Linked List search for the last element and then adding and therefore the time complexity would be O(n) (In terms of Big Oh only). Or is it indexing to the end of the list, realizing that the end of the list is say <code>stocks[5]</code> then inserting a new node referencing the new data at the end of the list?</p>
  
  <p>So my question is, is <code>addLast()</code> operation for a linked list time complexity of O(n) or O(1)?</p>
  
  <p>Post below for any clarifications</p>