Open
Conversation
CheezItMan
reviewed
Sep 28, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
Nicely done Hannah, thanks for getting this in. You hit the learning goals here with a number of extras. Take a look at my comments regarding time complexity as you missed several time complexities here.
Comment on lines
+19
to
+23
| # method to add a new node with the specific data value in the linked list | ||
| # insert the new node at the beginning of the linked list | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def add_first(value) |
Comment on lines
+29
to
+33
| # method to find if the linked list contains a node with specified value | ||
| # returns true if found, false otherwise | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def search(value) |
Comment on lines
+42
to
+46
| # method to return the max value in the linked list | ||
| # returns the data value and not the node | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def find_max |
There was a problem hiding this comment.
👍 , however the space complexity is O(1) since you're not building a new list.
Comment on lines
+59
to
+63
| # method to return the min value in the linked list | ||
| # returns the data value and not the node | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def find_min |
Comment on lines
+76
to
+79
| # method that returns the length of the singly linked list | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def length |
Comment on lines
+186
to
+191
| # checks if the linked list has a cycle. A cycle exists if any node in the | ||
| # linked list links to a node already visited. | ||
| # returns true if a cycle is found, false otherwise. | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def has_cycle |
There was a problem hiding this comment.
👍 , but what would the time complexity be?
Comment on lines
+206
to
+211
| # Additional Exercises | ||
| # returns the value in the first node | ||
| # returns nil if the list is empty | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def get_first |
Comment on lines
+216
to
+219
| # method that inserts a given value as a new last node in the linked list | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def add_last(value) |
There was a problem hiding this comment.
This method works, but since you traverse the list until the end of the list... the time complexity is O(n)
Comment on lines
+232
to
+236
| # method that returns the value of the last node in the linked list | ||
| # returns nil if the linked list is empty | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def get_last |
There was a problem hiding this comment.
Similar issues to the above method.
Comment on lines
+245
to
+249
| # method to insert a new node with specific data value, assuming the linked | ||
| # list is sorted in ascending order | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def insert_ascending(value) |
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.