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

Caballero- SPRUCE #61

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

Caballero- SPRUCE #61

wants to merge 3 commits into from

Conversation

Sanderspat
Copy link

No description provided.

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

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

Looks like you are missing the last two problems!

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(1) accessing it only on
# Space Complexity: O(1) no new data structure being created
def get_first(self):

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) constant time, since new data structure is being created but its small
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.

👍

pass

self.head = Node(value,self.head)

# method to find if the linked list contains a node with specified value
# returns true if found, false otherwise
# Time Complexity: ?
# Space Complexity: ?
def search(self, value):

Choose a reason for hiding this comment

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

👍

# method to find if the linked list contains a node with specified value
# returns true if found, false otherwise
# Time Complexity: ?
# Space Complexity: ?
def search(self, value):
pass
current = self.head
while current is not None:

Choose a reason for hiding this comment

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

we can shorten it to:

Suggested change
while current is not None:
while current:

Comment on lines 33 to 34
# Time Complexity: ?
# Space Complexity: ?

Choose a reason for hiding this comment

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

What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?


# method that returns the length of the singly linked list
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: 0(1) constant time

Choose a reason for hiding this comment

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

This should be O(n). The while loop is dependent upon the length of the linked list (ie, the input) to find the appropriate node

length += 1
current = current.next

return length

Choose a reason for hiding this comment

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

Move this line out of the while loop; otherwise, it will return immediately after the first iteration:

Suggested change
return length
return length


# method that returns the value at a given index in the linked list
# index count starts at 0
# returns None if there are fewer nodes in the linked list than the index value
# Time Complexity: ?
# Space Complexity: ?
def get_at_index(self, index):
pass
if self.length() < index:

Choose a reason for hiding this comment

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

love this! use those helper methods!

length += 1
current = current.next

return length

# method that returns the value at a given index in the linked list
# index count starts at 0
# returns None if there are fewer nodes in the linked list than the index value
# Time Complexity: ?
# Space Complexity: ?
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.

great start, but if the index is less than the length of the linked list, how do we find the appropriate node value at that index?


# method that returns the value at a given index in the linked list
# index count starts at 0
# returns None if there are fewer nodes in the linked list than the index value
# Time Complexity: ?
# Space Complexity: ?
def get_at_index(self, index):
pass
if self.length() < index:
return None

# method that returns the value of the last node in the linked list
# returns None if the linked list is empty
# Time Complexity: ?
# Space Complexity: ?
def get_last(self):

Choose a reason for hiding this comment

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

How do we travel to the down to the last node and return its value?

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