-
Notifications
You must be signed in to change notification settings - Fork 48
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
Time - Hannah T #42
base: master
Are you sure you want to change the base?
Time - Hannah T #42
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.
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.
# 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) |
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.
👍
# 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) |
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.
👍
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 , however the space complexity is O(1) since you're not building a new list.
# 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 |
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.
👍
# method that returns the length of the singly linked list | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def length |
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.
👍
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 , but what would the time complexity be?
# 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 |
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.
👍
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method works, but since you traverse the list until the end of the list... the time complexity is O(n)
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar issues to the above method.
# 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) |
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.