Skip to content

Lilly C16 Pine#64

Open
waterlilly169 wants to merge 2 commits intoAda-C16:masterfrom
waterlilly169:master
Open

Lilly C16 Pine#64
waterlilly169 wants to merge 2 commits intoAda-C16:masterfrom
waterlilly169:master

Conversation

@waterlilly169
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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

# Space Complexity: ?
# Time Complexity: O(1)?
# Space Complexity: O(1)?
def get_first(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
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

# insert the new node at the beginning of the linked list
# Time Complexity: ?
# Space Complexity: ?
def add_first(self, value):
Copy link
Copy Markdown

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:
Copy link
Copy Markdown

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:
Copy link
Copy Markdown

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:

# method that returns the length of the singly linked list
# Time Complexity: ?
# Space Complexity: ?
def length(self):
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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

# Space Complexity: ?
# Time Complexity: O(n)?
# Space Complexity: O(1)?
def reverse(self):
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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

# returns true if a cycle is found, false otherwise.
# Time Complexity: ?
# Space Complexity: ?
def has_cycle(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 interesting approach!

Comment thread linked_list/linked_list.py Outdated
Comment on lines 228 to 229
# Time Complexity: ?
# Space Complexity: ?
Copy link
Copy Markdown

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
Copy Markdown
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