lib/linked_list.rb
# Time complexity O(n)--have to traverse entire linked list to find the end where we add a new node
# Space complexity - O(1) -no new data structures added. Just adding a single entry.
Time complexity O(n)--have to traverse entire linked list to find the end where we add a new node
Space complexity - O(1) -no new data structures added. Just adding a single entry.
Time complexity O ( n ) -- have to traverse entire linked list to find the end where we add a new node Space complexity - O ( 1 ) - no new data structures added . Just adding a single entry .
def add_last(data)
    new_node = Node.new(data, nil)
    if @head.nil?
      @head = new_node
      else
    current = @head
    until current.next.nil?
      current = current.next
    end
    current.next = new_node
    end
  end
def add_last ( data ) new_node = Node . new ( data , nil ) if @head . nil? @head = new_node else current = @head until current . next . nil? current = current . next end current . next = new_node end end
Time complexity O(n)--have to traverse entire linked list to find the end where we add a new node
Space complexity - O(1) -no new data structures added.
Time complexity O ( n ) -- have to traverse entire linked list to find the end where we add a new node Space complexity - O ( 1 ) - no new data structures added .
#loop through linked list until last item is found and then add new item
data
<not_specific>