Open
Conversation
kyra-patton
reviewed
Jul 28, 2022
kyra-patton
left a comment
There was a problem hiding this comment.
✨ Really nice work, Diana. Since you chose to do a doubly linked lists, I left a few comments about refactoring some of your methods for doubly linked lists. Let me know what questions you have.
🟢
| def __init__(self, value, next_node = None, prev_node = None): | ||
| self.value = value | ||
| self.next = next_node | ||
| self.previous = prev_node #This line because this is a doubly linked list |
| # Space Complexity: ? | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def get_first(self): |
| # Space Complexity: ? | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def add_first(self, value): |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def search(self, value): |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def length(self): |
|
|
||
| # method to return the max value in the linked list | ||
| # returns the data value and not the node | ||
| def find_max(self): |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def delete(self, value): |
Comment on lines
+143
to
+144
| if new.value == value: | ||
| break |
There was a problem hiding this comment.
We generally try and avoid using break statements unless really necessary. Might you be able to refactor your code to eliminate this?
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) |
There was a problem hiding this comment.
🪐 Space complexity will be O(n) here because the function creates a helper_list which will end up holding all the nodes in the linked list
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def reverse(self): |
There was a problem hiding this comment.
Since you have a doubly linked list you also need to think about how you redirect your previous and tail pointers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.