Skip to content

Conversation

@saintmedusa
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.

Nice work Yaz, thanks for getting this in. The methods you implementing are pretty well done. You did miss some entries for time/space complexity. Otherwise excellent work.

Comment on lines +19 to +23
# 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: 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 29
if @head
second = @head
@head = Node.new(value, second)
else
@head = Node.new(value)
end

Choose a reason for hiding this comment

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

Suggested change
if @head
second = @head
@head = Node.new(value, second)
else
@head = Node.new(value)
end
@head = Node.new(value, @head)

Comment on lines +34 to +36
# Time Complexity: O(n)
# 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.

👍 Nice helper method

Comment on lines +43 to +45
# method to return the max value in the linked list
# returns the data value and not the node
def find_max

Choose a reason for hiding this comment

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

👍

Comment on lines +62 to +64
# Time Complexity: O(n)
# Space Complexity: O(1)
def find_min

Choose a reason for hiding this comment

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

👍

Comment on lines +121 to +124
# method to delete the first node found with specified value
# Time Complexity: O(n)
# Space Complexity: O(1)
def delete(value)

Choose a reason for hiding this comment

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

👍

Comment on lines +133 to +137
# method to reverse the singly linked list
# note: the nodes should be moved and not just the values in the nodes
# Time Complexity: O(n)
# Space Complexity: O(n)
def reverse

Choose a reason for hiding this comment

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

👍

Comment on lines +149 to +153
## Advanced Exercises
# returns the value at the middle element in the singly linked list
# Time Complexity: O(n)
# Space Complexity: O(1)
def find_middle_value

Choose a reason for hiding this comment

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

👍

Comment on lines +161 to +163
# Time Complexity: O(n)
# Space Complexity: O(1)
def find_nth_from_end(n)

Choose a reason for hiding this comment

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

👍

Comment on lines +198 to +200
# Time Complexity: ?
# Space Complexity: ?
def get_first

Choose a reason for hiding this comment

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

👍

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