-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Earth - Ringo #22
base: master
Are you sure you want to change the base?
Earth - Ringo #22
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done Ringo, you hit the learning goals and did a number of the extra methods. Very well done. I left a few minor comments, but this is quite well done.
# Time Complexity: O(1), will take same amount of time regardless of the length of the list | ||
# Does not have to perform any additional operations to move the existing nodes | ||
# Space Complexity: O(1), needs space for one new node | ||
# Does not need any additional space for existing nodes as they are unaffected | ||
# Would be O(n) where n is the size of the value being saved to the new node, | ||
# but if all nodes are integers and therefore comparable sizes, n is constant | ||
def add_first(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n), in the worst case scenario needs to check every single | ||
# node in a linked list of n length | ||
# Space Complexity: O(n), just needs to save one node to a variable | ||
def search(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 , but the space complexity for the iterative solution is O(1)
# Time Complexity: O(n). Will need to check every node in linked list of n length | ||
# Space Complexity: O(1). Will need two running variables regardless of length of list | ||
def find_max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n). Will need to check every node in linked list of n length | ||
# Space Complexity: O(1). Will need two running variables regardless of length of list | ||
def find_min |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(1), checking the head node takes one operation | ||
# Space Complexity: O(1) assuming all nodes have comparable data sizes, same size return value regardless | ||
def get_first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n), n = length of linked list | ||
# Space Complexity: O(1) | ||
def get_last |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n), n = length of linked list | ||
# Space Complexity: O(1) | ||
def find_middle_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 , good use of a fast and slow pointer
# Time Complexity: O(n), n = length of linked list | ||
# Space Complexity: O(1) | ||
def find_nth_from_end(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the lead pointer.
# Time Complexity: O(n), n = length of linked list | ||
# Space Complexity: O(n), n = number of nodes (length of linked list) | ||
def has_cycle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is one solution. However since you are using .include?
this solution is O(n^2) in time complexity.
You can do it in O(n) with a fast and slow pointer.
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def insert_ascending(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
No description provided.