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

Lilly C16 Pine #64

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

Lilly C16 Pine #64

wants to merge 2 commits into from

Conversation

waterlilly169
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

You are missing a lot of your space/time complexity explanations

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

👍

Copy link
Author

Choose a reason for hiding this comment

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

resubmitted with questions filled out


return self.head.value

# method to add a new node with the specific data value in the linked list
# insert the new node at the beginning of the linked list
# Time Complexity: ?
# Space Complexity: ?
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.

👍

pass
current = self.head

while current != 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 != None:
while current:

current = self.head

count = 0
while current != 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 != None:
while current:

if current.value == value:
return True
current = current.next
return False

# method that returns the length of the singly linked list
# Time Complexity: ?
# Space Complexity: ?
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 +138 to +149
while current is not None:
if current.value == value:
break
prev = current
current = current.next

if current == None:
return None

prev.next = current.next

current = 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, too, to make it more readable:

Suggested change
while current is not None:
if current.value == value:
break
prev = current
current = current.next
if current == None:
return None
prev.next = current.next
current = None
while current is not None:
if current.next.value == value:
current.next = current.next.next
current = current.next

We don't need to re-assign current to None nor return None

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)?
# Space Complexity: O(1)?
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 +187 to +191
current = self.head
count = 0
while current:
count += 1
current = current.next

Choose a reason for hiding this comment

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

hmm where have we seen this already? Maybe we can call length to get the number of nodes

return current.value




# checks if the linked list has a cycle. A cycle exists if any node in the
# linked list links to a node already visited.
# returns true if a cycle is found, false otherwise.
# Time Complexity: ?
# Space Complexity: ?
def has_cycle(self):

Choose a reason for hiding this comment

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

👍 interesting approach!

Comment on lines 228 to 229
# Time Complexity: ?
# Space Complexity: ?

Choose a reason for hiding this comment

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

What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?

@waterlilly169
Copy link
Author

Resubmitted with time complexity

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