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

Sockets - Evelynn #25

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

Conversation

evelynnkaplan
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Well done! You hit the major learning goals with only a few missteps. Take a look at my comments and let me know if you have any questions.

# Time Complexity: O(1)
# Space Complexity: O(1)
def add_first(value)
if self.length != 0

Choose a reason for hiding this comment

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

You can do this without calling the length method since it doesn't matter how long the list is to add an element to the front.

Also since you're doing .length, this causes your algorithm to be O(n) time complexity.

def find_min
raise NotImplementedError
current = @head
(self.length - 1).times do

Choose a reason for hiding this comment

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

Since .length is a method and it traverses the list, it would be good to save that result in a variable rather than calling the method multiple times.

end

middle = self.length / 2

middle_value = self.get_at_index(middle)

Choose a reason for hiding this comment

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

Smart!

# Space Complexity
def add_last(value)
raise NotImplementedError
index_of_n = self.length - 1 - n

Choose a reason for hiding this comment

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

Why not use the get_at_index method again?

# Time Complexity: O(n) where n is the number of nodes in the list
# Space Complexity: O(1)
def has_cycle
if self.length <= 1

Choose a reason for hiding this comment

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

Just a point, if it has a cycle, then the length method will get stuck in an infinite loop.

if a == b
return true
else
a = a.next

Choose a reason for hiding this comment

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

This won't work if the cycle is more than 2 nodes long.

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