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

Solve standard linked list problems #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cecomfort
Copy link

@cecomfort cecomfort commented Sep 4, 2017

Linked Lists

Questions:

  1. Justification for space complexity for inert method.
  2. Justification for time complexity for nth-from-beginning method.
  3. find_middle_value2: What modifications would provide the upper value when the list has an even number of nodes?
  4. Justification for time complexity of has_cycle method. It seems worse than just O(N).

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)
What is the space complexity of the insert method? Provide justification. O(1) -> memory allocation constant regardless of size of linked list. OR O(n), where n is the value to be inserted? memory allocation depends on size of input value??
What is the time complexity of the search method? Provide justification. O(N) => By average, visit half of elements and the constant of 1/2 drops out. Worst case, visit all elements.
What is the space complexity of the search method? Provide justification. O(1) => No matter the size of the list, only need 1 temp.
What is the time complexity of the find_max method? Provide justification. O(N) => Have to visit each element
What is the space complexity of the find_max method? Provide justification. O(1) => Regardless of list size, just have 1 temp var
What is the time complexity of the find_min method? Provide justification. same as max
What is the space complexity of the find_min method? Provide justification. same as max
What is the time complexity of the length method? Provide justification. O(N) => have to visit each element to determine length
What is the space complexity of the length method? Provide justification. O(1) => Have two temps, regardless of linked list size
What is the time complexity of the find_nth_from_beginning method? Provide justification. Not dependent on linked list size, but index passed in. O(n), where n = index to find
What is the space complexity of the find_nth_from_beginning method? Provide justification. O(1) => memory allocation constant regardless of list size. Just need a temp var.
What is the time complexity of the insert_ascending method? Provide justification. O(N) => may have to visit each node
What is the space complexity of the insert_ascending method? Provide justification. O(1) => Always creating just 1 new node and 1 temp var if linked list size is 1 or 100
What is the time complexity of the visit method? Provide justification. O(N) => have to visit each element in the linked list once
What is the space complexity of the visit method? Provide justification. O(1) => regardless of size of list, only need to create one temp variable
What is the time complexity of the delete method? Provide justification. O(N) => may have to iterate over entire list looking for value.
What is the space complexity of the delete method? Provide justification. O(1) => memory allocation constant regardless of list size
What is the time complexity of the reverse method? Provide justification. O(N) => Iterate througth the linked list once
What is the space complexity of the reverse method? Provide justification. O(1) => memory allocation not dependent on linked list size
What is the time complexity of the find_middle_value method? Provide justification. O(N) => constant of 1/2 will drop in bigO
What is the space complexity of the find_middle_value method? Provide justification. O(1) => memory needed not dependent on linked list size.
What is the time complexity of the find_nth_from_end method? Provide justification. O(N)
What is the space complexity of the find_nth_from_end method? Provide justification. O(1)
What is the time complexity of the has_cycle method? Provide justification. O(N) => seems worse than this? How do you not know it is N^2?
What is the space complexity of the has_cycle method? Provide justification. O(1)

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