title: Single Linked Lists and Time Complexity
body: <p>I'm just starting my jurney with topic of Data Structures and working with some Single linked lists. I crated a two type of lists:</p>
  <ol>
  <li>Where Nodes are added to the head of the list checking from the tail (Time complexity O(n))</li>
  <li>Where Nodes are added to the head of the list checking only the head (Time complexity O(1))</li>
  </ol>
  <p>I wanted to run test and check the output of my code and more or less it's correct but I noticed this weird noises and I don't know why they are there. Do you guys have any clue on that?</p>
  <pre class="lang-py prettyprint-override"><code>class Node(object):
          def __init__(self, data = None):
              self.data = data
              self.next = None
  
          def _str_(self):
              return str(self.data)
  
  
  class SonglyLinkedList_tail:
          def __init__(self):
              self.tail = None
              self.size = 0
  
          def append(self, data):
              node = Node(data)
              if not self.tail:
                  self.tail = node
              else:
                  current = node
                  while current.next:
                      current = current.next
                  current.next = node
              self.size += 1
  
  class SinglyLinkedList_head:
          def __init__(self):
              self.tail = None
              self.head = None
              self.size = 0
  
          def append(self, data):
              node = Node(data)
              if self.head:
                  self.head.next = node
                  self.head = node
              else:
                  self.head = node
                  self.tail = node
              self.size += 1
  
          def iter(self):
              current = self.tail
              if current.next:
                  val = current.data
  
                  current = current.next
  
  tail = SonglyLinkedList_tail()
  head = SinglyLinkedList_head()
  xes = []
  yes = []
  for i in range(5000):
          xes.append(i)
          list = random.sample(range(1, 100000), i)
          start_time = float(time.time())
          stop_time = float(time.time())
          for number in list:
              tail.append(number)
          stop_time = time.time()
          run_time = stop_time-start_time
          yes.append(run_time)
  
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/9UvwJ.png" rel="nofollow noreferrer">Time complexity for O(n) algorithm</a>
  <a href="https://i.stack.imgur.com/wS1i2.png" rel="nofollow noreferrer">Time complexity for O(1) algorithm</a></p>
  <p>EDIT:</p>
  <p>Photo after suggested changes in algorithm 1 <a href="https://i.stack.imgur.com/HLd9F.png" rel="nofollow noreferrer">First algorithm time complexity O(n^2)</a></p>