Skip to content

Conversation

@J-C-L
Copy link

@J-C-L J-C-L commented Aug 31, 2017

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), constant. Always inserting at head, so time required doesn't change with list size.
What is the space complexity of the insert method? Provide justification. O(1), constant. No extra storage needed.
What is the time complexity of the search method? Provide justification. O(n), linear. May need to traverse whole list to find element
What is the space complexity of the search method? Provide justification. O(1), constant. No extra storage needed.
What is the time complexity of the find_max method? Provide justification. O(n), linear. Will need to traverse whole list to find greatest element
What is the space complexity of the find_max method? Provide justification. O(1), constant. No extra storage needed beyond a single variable.
What is the time complexity of the find_min method? Provide justification. O(n), linear. Will need to traverse whole list to find smallest element
What is the space complexity of the find_min method? Provide justification. O(1), constant. No extra storage needed beyond a single variable.
What is the time complexity of the length method? Provide justification. O(n), linear. Will need to traverse whole list to find the length
What is the space complexity of the length method? Provide justification. O(1), constant. No extra storage needed beyond a single variable.
What is the time complexity of the find_nth_from_beginning method? Provide justification. For a fixed n, the time complexity is constant. You only traverse the first n elements, so the time is independent of list length.
What is the space complexity of the find_nth_from_beginning method? Provide justification. O(1), constant. No extra storage needed beyond a single variable.
What is the time complexity of the insert_ascending method? Provide justification.
O(n), linear. May need to traverse whole list to find insertion point.
What is the space complexity of the insert_ascending method? Provide justification. O(1), constant. No extra storage needed.
What is the time complexity of the visit method? Provide justification. O(n), linear. Will need to traverse whole list.
What is the space complexity of the visit method? Provide justification. O(1), constant. No extra storage needed.
What is the time complexity of the delete method? Provide justification. O(n), linear. May need to traverse whole list to find value to delete or decide no such value is present.
What is the space complexity of the delete method? Provide justification. O(1), constant. No extra storage needed.
What is the time complexity of the reverse method? Provide justification. O(n), linear. Will need to traverse whole list to complete the reversal.
What is the space complexity of the reverse method? Provide justification. O(1), constant. No extra storage needed beyond an additional variable.
What is the time complexity of the find_middle_value method? Provide justification. O(n), linear. (Could say 1.5n, since traversing the list 1.5 times, but this is still linear. )
What is the space complexity of the find_middle_value method? Provide justification. O(1), constant. No extra storage needed.
What is the time complexity of the find_nth_from_end method? Provide justification. O(n), linear. (Could say ~2n, since traversing the list almost 2 times, but this is still linear. )
What is the space complexity of the find_nth_from_end method? Provide justification. O(1), constant. No extra storage needed beyond an extra variable.
What is the time complexity of the has_cycle method? Provide justification. O(n), linear. (Might be A*n, where A is a rational number, since we may have to traverse the list mulitple times, but this is still linear. )
What is the space complexity of the has_cycle method? Provide justification. O(1), constant. No extra storage needed.

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.

1 participant