Skip to content
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

Addie's Linked List #13

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

add2point71dots
Copy link

Linked Lists

Congratulations! You're submitting your assignment.

Comprehension Questions

What is the time and space complexity for each method you implemented? Provide justification.

Question Answer
What is the time complexity of the insert method? Provide justification. O(1) because I'm just replacing the head no matter the size of the list.
What is the space complexity of the insert method? Provide justification. O(1) because I'm only creating one new node, no matter the size of the list.
What is the time complexity of the search method? Provide justification. O(n) because I'm stepping through the list once.
What is the space complexity of the search method? Provide justification. O(1) because I'm not creating anything that depends on the size of the list.
What is the time complexity of the find_max method? Provide justification. O(n) because I'm stepping through the list once.
What is the space complexity of the find_max method? Provide justification. O(1) because I'm not creating anything that depends on the size of the list.
What is the time complexity of the find_min method? Provide justification. O(n) because I'm stepping through the list once.
What is the space complexity of the find_min method? Provide justification. O(1) because I'm not creating anything that depends on the size of the list.
What is the time complexity of the length method? Provide justification. O(n) because I'm stepping through the list once.
What is the space complexity of the length method? Provide justification. O(1) because I'm not creating anything that depends on the size of the list.
What is the time complexity of the find_nth_from_beginning method? Provide justification. O(n) because I'm stepping through the list n times.
What is the space complexity of the find_nth_from_beginning method? Provide justification. O(1) because I'm not creating anything that depends on n.
What is the time complexity of the insert_ascending method? Provide justification. O(n) because I'm stepping through the list once.
What is the space complexity of the insert_ascending method? Provide justification. O(1) because I'm not creating anything that depends on the size of the input.
What is the time complexity of the visit method? Provide justification. O(n) because I'm stepping through the list once to print each element.
What is the space complexity of the visit method? Provide justification. O(1) because I'm not storing anything that depends on the size of the list.
What is the time complexity of the delete method? Provide justification. O(n) because I'm (potentially) stepping through the list once.
What is the space complexity of the delete method? Provide justification. O(1) because I'm not creating anything that depends on the size of the input.
What is the time complexity of the reverse method? Provide justification. O(n) because I'm stepping through the list once to reverse it.
What is the space complexity of the reverse method? Provide justification. O(1) because I'm just creating temporary variables that do not depend on the size of the list.
What is the time complexity of the find_middle_value method? Provide justification. O(n) because I'm stepping through the array once with one pointer and through half with the other.
What is the space complexity of the find_middle_value method? Provide justification. O(1) because I'm not creating anything that depends on the size of the input.
What is the time complexity of the find_nth_from_end method? Provide justification. O(n) because I'm stepping through once, albeit with two pointers.
What is the space complexity of the find_nth_from_end method? Provide justification. O(1) because I'm not creating anything that depends on the size of the input.
What is the time complexity of the has_cycle method? Provide justification. O(n). While it might cycle through part of the list more than once, there are no nested loops. I'm just using two pointers to individually step through the list.
What is the space complexity of the has_cycle method? Provide justification. O(1) because I'm not creating anything dependent on the size of the input.

@shrutivanw
Copy link
Collaborator

Nice work!

And now I know a little bit of Go, thanks to you. :-) It looks similar to C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants