Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
✨ Nice work on the implementation, Ro. I left some comments on time and space complexity. Let me know what questions you have.
🟢
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| self.head = None |
| # Space Complexity: ? | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def add_first(self, value): |
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) |
There was a problem hiding this comment.
⏱ Time complexity is O(n) here since you have to loop through all of the nodes in the worst case
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) |
There was a problem hiding this comment.
🪐 Space complexity is O(1) here since you aren't creating any additional data structures in your function body that are proportional to the size of the input
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def get_at_index(self, index): |
There was a problem hiding this comment.
🪐 Same as length - you aren't creating any additional data structures here
|
|
||
| # method to return the max value in the linked list | ||
| # returns the data value and not the node | ||
| def find_max(self): |
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) |
| # method to print all the values in the linked list | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(1) after element is found; O(n) prior |
There was a problem hiding this comment.
⏱ Time complexity is O(n) because this function iterates through the entire list and adds them to an array to print out
🪐 Space complexity is O(n) because you are creating an additional array helper_list which becomes length n where n is the length of the linked list
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) |
There was a problem hiding this comment.
🪐 Space complexity would be O(1) here again because you aren't creating any additional data structures whose size is proportional to the size of your linked list
| self.head = previous | ||
|
|
||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) |
No description provided.