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

Earth - Ringo #22

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

Earth - Ringo #22

wants to merge 1 commit into from

Conversation

ringolingo
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 Ringo, you hit the learning goals and did a number of the extra methods. Very well done. I left a few minor comments, but this is quite well done.

Comment on lines +21 to 27
# Time Complexity: O(1), will take same amount of time regardless of the length of the list
# Does not have to perform any additional operations to move the existing nodes
# Space Complexity: O(1), needs space for one new node
# Does not need any additional space for existing nodes as they are unaffected
# Would be O(n) where n is the size of the value being saved to the new node,
# but if all nodes are integers and therefore comparable sizes, n is constant
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 +35 to 38
# Time Complexity: O(n), in the worst case scenario needs to check every single
# node in a linked list of n length
# Space Complexity: O(n), just needs to save one node to a variable
def search(value)

Choose a reason for hiding this comment

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

👍 , but the space complexity for the iterative solution is O(1)

Comment on lines +50 to 52
# Time Complexity: O(n). Will need to check every node in linked list of n length
# Space Complexity: O(1). Will need two running variables regardless of length of list
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 +67 to 69
# Time Complexity: O(n). Will need to check every node in linked list of n length
# Space Complexity: O(1). Will need two running variables regardless of length of list
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 +86 to 88
# Time Complexity: O(1), checking the head node takes one operation
# Space Complexity: O(1) assuming all nodes have comparable data sizes, same size return value regardless
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 +209 to 211
# Time Complexity: O(n), n = length of linked list
# 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.

👍

Comment on lines +224 to 226
# Time Complexity: O(n), n = length of linked list
# 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.

👍 , good use of a fast and slow pointer

Comment on lines +246 to 248
# Time Complexity: O(n), n = length of linked list
# 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.

I like the lead pointer.

Comment on lines +272 to 274
# Time Complexity: O(n), n = length of linked list
# Space Complexity: O(n), n = number of nodes (length of linked list)
def has_cycle

Choose a reason for hiding this comment

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

That is one solution. However since you are using .include? this solution is O(n^2) in time complexity.

You can do it in O(n) with a fast and slow pointer.

Comment on lines +290 to 292
# Time Complexity: O(n)
# Space Complexity: O(1)
def insert_ascending(value)

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