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

Maple - Monica C. #63

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

Maple - Monica C. #63

wants to merge 14 commits into from

Conversation

mcatcruz
Copy link

@mcatcruz mcatcruz commented Jul 7, 2022

No description provided.

# 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.

👍

Comment on lines +28 to +30
new_node = Node(value)
new_node.next = self.head
self.head = new_node

Choose a reason for hiding this comment

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

this works just fine! We can also exploit the default parameter in the Node class and add the next pointer all at once:

Suggested change
new_node = Node(value)
new_node.next = self.head
self.head = new_node
self.head = Node(value, self.head)

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# 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.

👍

def search(self, value):
pass
current_node = self.head
while current_node is not None:

Choose a reason for hiding this comment

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

we can shorten this to:

Suggested change
while current_node is not None:
while current_node:

pass
node_count = 0
current_node = self.head
while current_node is not None:

Choose a reason for hiding this comment

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

Suggested change
while current_node is not None:
while current_node:

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(1)
def delete(self, value):

Choose a reason for hiding this comment

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

👍

current_node = current_node.next

# When last node is found, I want to append new_node to it.
current_node.next = new_node

# method to return the max value in the linked list
# returns the data value and not the node
def find_max(self):

Choose a reason for hiding this comment

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

👍

current_node = current_node.next

previous_node.next = current_node.next
current_node = None

Choose a reason for hiding this comment

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

Suggested change
current_node = None

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)
def reverse(self):

Choose a reason for hiding this comment

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

👍

Comment on lines +178 to +179
# Time Complexity: O(n)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

your time/space complexity is correct! But how could we solve this so that we don't need to make new data structures? How could we use a few pointers that keep track of the previous node, the current node, and the next node?

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