Skip to content

Scissors - Mai T.#59

Open
truongmt89 wants to merge 1 commit intoAda-C15:masterfrom
truongmt89:master
Open

Scissors - Mai T.#59
truongmt89 wants to merge 1 commit intoAda-C15:masterfrom
truongmt89:master

Conversation

@truongmt89
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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. Take a look at my comments and let me know what questions you have.

Comment on lines +16 to 18
# Time Complexity: O(1)
# Space Complexity: O(n)
def get_first(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 However space complexity is O(1) since it doesn't add any nodes to the list.

Comment on lines +27 to 29
# Time Complexity: O(1)
# Space Complexity: O(n)
def add_first(self, value):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Also O(1) for space complexity since the method only ever adds 1 node to the list.

Comment on lines +35 to 37
# Time Complexity: O(n)
# Space Complexity: O(n)
def search(self, value):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 However the space complexity is O(1) since it doesn't increase the size of the list.

Comment on lines +46 to 48
# Time Complexity: O(n)
# Space Complexity: O(n)
def length(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Also O(1) for space complexity.

Comment on lines +59 to 61
# Time Complexity: O(n)
# Space Complexity: O(n)
def get_at_index(self, index):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Also O(1) for space complexity

Comment on lines +118 to +119
current_node = self.head
if current_node.value == value:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You need to check to see if the linked list is empty so

        if self.head == None
            return

self.head = current_node.next
return
while current_node != None:
if current_node.next.value == value:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you want to check current_node.next.value you should also check to see if current_node.next is None

# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(n)
def delete(self, value):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ This one isn't working. See my comments below.

previous_node = None
current_node = self.head
while current_node != None:
next_node = current_node
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
next_node = current_node
next_node = current_node.next

Comment on lines +142 to 144
# Time Complexity: O(n)
# Space Complexity: O(1)
def reverse(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Also not quite working

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