-
Notifications
You must be signed in to change notification settings - Fork 28
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
Erica Case - Linked-List #1
base: master
Are you sure you want to change the base?
Conversation
linked_list.py
Outdated
# method to find if the linked list contains a node with specified value | ||
# returns true if found, false otherwise | ||
def search(value): | ||
pass |
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.
Send me a slack DM, when you complete this. So I know to review then.
linked_list.py
Outdated
|
||
node = self.__head | ||
max = node.get_data() | ||
while node.next_node != None: |
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.
Should this be node != None:
instead of node.next_node != None:
? Check if you get the right result when the last node in the linked list has the max value.
mid_val = node.get_data() | ||
|
||
while node.next_node and node.next_node.next_node: | ||
mid_val = node.next_node.get_data() |
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.
Let's say the linked list is 1 -> 2 -> 3 -> 4 -> 5. I expect to get back 3, but this method will return 4. Think more on what the algorithm should look like.
# # 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. | ||
def has_cycle(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.
The time complexity for has_cycle will be O(n) and not O(1) - since it will depend on the length of the list.
return False | ||
slow_loop = self.__head | ||
fast_loop = self.__head.next_node | ||
while fast_loop.next_node.next_node: |
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.
What happens if fast_loop.next_node is None:? null dereference issue. Check for fast_loop.next_node before checking for fast_loop.next_node.next_node.
Restricted Array
Congratulations! You're submitting your assignment.
Comprehension Questions
What is the time and space complexity for each method you implemented? Provide justification.