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

Ro Linked List Python #58

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

Ro Linked List Python #58

wants to merge 1 commit into from

Conversation

ropeeps
Copy link

@ropeeps ropeeps commented Jun 8, 2022

No description provided.

Copy link

@kyra-patton kyra-patton 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 on the implementation, Ro. I left some comments on time and space complexity. Let me know what questions you have.

🟢

Comment on lines -16 to +11
# Time Complexity: ?
# Space Complexity: ?
self.head = None

Choose a reason for hiding this comment

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

⏱🪐Time and space complexity?

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(1)
# Space Complexity: O(1)
def add_first(self, value):

Choose a reason for hiding this comment

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

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(1)
# Space Complexity: O(1)

Choose a reason for hiding this comment

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

⏱ Time complexity is O(n) here since you have to loop through all of the nodes in the worst case

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

🪐 Space complexity is O(1) here since you aren't creating any additional data structures in your function body that are proportional to the size of the input

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)
def get_at_index(self, index):

Choose a reason for hiding this comment

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

🪐 Same as length - you aren't creating any additional data structures here


# method to return the max value in the linked list
# returns the data value and not the node
def find_max(self):

Choose a reason for hiding this comment

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

⏱🪐 Time and space complexity?

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

🪐 Again - O(1) space complexity

# method to print all the values in the linked list
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(1) after element is found; O(n) prior

Choose a reason for hiding this comment

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

⏱ Time complexity is O(n) because this function iterates through the entire list and adds them to an array to print out
🪐 Space complexity is O(n) because you are creating an additional array helper_list which becomes length n where n is the length of the linked list

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

🪐 Space complexity would be O(1) here again because you aren't creating any additional data structures whose size is proportional to the size of your linked list

self.head = previous

# Time Complexity: O(n)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

🪐Space complexity is O(1) again

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