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

Time - Yoyo #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Time - Yoyo #38

wants to merge 1 commit into from

Conversation

ydunbar
Copy link

@ydunbar ydunbar commented Aug 27, 2020

No description provided.

@ydunbar ydunbar changed the title Added functions Yoyo - Time Aug 27, 2020
@ydunbar ydunbar changed the title Yoyo - Time Time - Yoyo Aug 27, 2020
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.

Some issues here and some existing syntax errors. Take a look at my comments and let me know what questions you have.

Comment on lines +21 to 23
# Time Complexity: O(1)
# Space Complexity: O(1)
def add_first(value)

Choose a reason for hiding this comment

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

👍

Comment on lines +24 to +30
new_node = Node.new(value)
if @head.nil?
@head = new_node
else
new_node.next = @head
@head = new_node
end

Choose a reason for hiding this comment

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

This can be simplified as:

Suggested change
new_node = Node.new(value)
if @head.nil?
@head = new_node
else
new_node.next = @head
@head = new_node
end
@head = Node.new(value, @head)

Comment on lines +35 to 37
# Time Complexity: O(1)
# Space Complexity: O(1)
def search(value)

Choose a reason for hiding this comment

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

👍 The time complexity here is O(n)

new_previous = current.next
new_current = new_previous.next
new_previous.next = current
current = new_current

Choose a reason for hiding this comment

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

Missingend

Suggested change
current = new_current
current = new_current
end

Comment on lines +137 to +146
if @head.nil?
return nil
end
previous = @head
current = @head
until current.data == value || current.nil?
previous = current
current = current.next
end
previous.next == current.next

Choose a reason for hiding this comment

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

You also need a check here to see if value is at the head of the list.

Suggested change
if @head.nil?
return nil
end
previous = @head
current = @head
until current.data == value || current.nil?
previous = current
current = current.next
end
previous.next == current.next
if @head.nil?
return nil
elsif @head.data == value
@head = @head.next
return
end
previous = @head
current = @head
until current.data == value || current.nil?
previous = current
current = current.next
end
previous.next == current.next

Comment on lines +120 to 122
# Time Complexity: O(n)
# Space Complexity: O(n)
def visit

Choose a reason for hiding this comment

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

👍 , but the space complexity is O(1) because you're not making a new list here.

Comment on lines +151 to 153
# Time Complexity: O(n)
# Space Complexity: O(1)
def reverse

Choose a reason for hiding this comment

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

⚠️ Looks like you have the right idea, but a missing end

Comment on lines +195 to 197
# Time Complexity: O(1)
# Space Complexity: O(1)
def get_first

Choose a reason for hiding this comment

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

👍

Comment on lines +206 to 208
# Time Complexity: O(n)
# Space Complexity: O(1)
def add_last(value)

Choose a reason for hiding this comment

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

👍

Comment on lines +223 to 225
# Time Complexity: O(1)
# Space Complexity: O(1)
def get_last

Choose a reason for hiding this comment

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

👍 , but the time complexity is O(n) since you're traveling to the end of the list.

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