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

Spruce - Angela Fan #71

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

Spruce - Angela Fan #71

wants to merge 2 commits into from

Conversation

fan-gela
Copy link

No description provided.

Copy link

@kyra-patton kyra-patton left a 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):

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):

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)

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):

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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 245 to 246
# Time Complexity: ?
# Space Complexity: ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱🪐 Time and space complexity?

Comment on lines 230 to 231
# Time Complexity: ?
# Space Complexity: ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱🪐 Time and space complexity?

Comment on lines 214 to 215
# Time Complexity: ?
# Space Complexity: ?

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):

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):

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

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