-
Notifications
You must be signed in to change notification settings - Fork 87
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
Spruce - Angela Fan #71
base: master
Are you sure you want to change the base?
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 Angela. I left some comments on time and space complexity, but overall it seems like you have a good understanding of linked lists.
🟢
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
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: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
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.
✨
|
||
# method to find if the linked list contains a node with specified value | ||
# returns true if found, false otherwise | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(1) |
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 is O(n) since in the worst case the node with the value you are searching for will be the last node in the list, and you will have to iterate through every node in the list.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
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: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
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: ? | ||
# Space Complexity: ? |
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 and space complexity?
# Time Complexity: ? | ||
# Space Complexity: ? |
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 and space complexity?
# Time Complexity: ? | ||
# Space Complexity: ? |
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 and space complexity?
previous = current | ||
current = next_node | ||
self.head = previous | ||
return previous | ||
|
||
## Advanced/ Exercises | ||
# returns the value at the middle element in the singly linked list | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def find_middle_value(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.
✨
current = current.next | ||
middle_value = current.value | ||
|
||
return middle_value | ||
|
||
# find the nth node from the end and return its value | ||
# assume indexing starts at 0 while counting to n | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def find_nth_from_end(self, 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.
You could also take advantage of the get_at_index
method you wrote
No description provided.