Conversation
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: 0(1) | ||
| # Space Complexity: 0(n) |
There was a problem hiding this comment.
This should be O(1), because we aren't creating any new data inside the function that is dependent on the size of the link
| # Space Complexity: ? | ||
| # Time Complexity: 0(1) | ||
| # Space Complexity: 0(n) | ||
| def get_first(self): |
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| # insert the new node at the beginning of the linked list | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def add_first(self, value): |
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| # method to delete the first node found with specified value | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def delete(self, value): |
| # Time Complexity: ? | ||
| # Space Complexity: ? |
There was a problem hiding this comment.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
| if not reversed_link: | ||
| next_node = current.next | ||
| current.next = None | ||
| reversed_link = current | ||
| current = next_node | ||
| else: |
There was a problem hiding this comment.
hmm I don't think we need this first if statement if we change the while loop to while current != None. I think starting reversed_link as None like you did and then going into the else statement will work
| current.next = reversed_link | ||
| reversed_link = current |
There was a problem hiding this comment.
we can get rid of these two lines if we change the while loop
No description provided.