-
Notifications
You must be signed in to change notification settings - Fork 68
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
Rock - N.Lucuab #63
base: master
Are you sure you want to change the base?
Rock - N.Lucuab #63
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.
Nice work Nyckolle, you hit the learning goals here. Well done.
# Time Complexity: O(1) | ||
# Space Complexity: O(1) - nothing new is being added, so memory is unaffected | ||
def get_first(self): |
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) | ||
# Space Complexity: O(1)? Only 1 node is being added, so 0(1) sounds right memory-wise | ||
def add_first(self, 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) - traverses the whole list | ||
# Space Complexity: O(1) - nothing new is being added, so memory is unaffected | ||
def search(self, 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) - traverses the list | ||
# Space Complexity: O(1) - no new node is being added, so memory is unaffected | ||
def length(self): |
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) - traverses the list to find value | ||
# Space Complexity: O(1) - no new node is being added, so memory is unaffected | ||
def get_at_index(self, index): |
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) - only inserts 1 value | ||
# Space Complexity: O(n) - traverses the list in order to find the end, and then adds on value | ||
def add_last(self, 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.
👍 The time complexity is O(n) because you traverse to the end of the list. The space complexity is O(1) because you only ever add one node.
while current.next != None: | ||
current = current.next | ||
# set current.next to the new_node | ||
current.next = new_node | ||
|
||
# method to return the max value in the linked list | ||
# returns the data value and not the node | ||
def find_max(self): |
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) - traverses list to find specified value | ||
# Space Complexity: O(1) - deletes only 1 value | ||
def delete(self, 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) - traverses list | ||
# Space Complexity: O(n) - prints out every 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) - traverses/reverses entire list | ||
# Space Complexity: O(1) - no new nodes are being added | ||
def reverse(self): |
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.
👍
Linked List project - passes all 27 required tests