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

Makhabat - Cedar #62

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

Conversation

makhabatmaksatbekova
Copy link

No description provided.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(1)
# Space Complexity: O(1)
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(n)
# Space Complexity: O(1)
def search(self, value):

Choose a reason for hiding this comment

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

👍

if self.head == None:
return False
current = self.head
while current != None:

Choose a reason for hiding this comment

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

we can shorten this to:

Suggested change
while current != None:
while current:

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(1)
def length(self):

Choose a reason for hiding this comment

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

👍

pass
lenght = 0
current = self.head
while current != None:

Choose a reason for hiding this comment

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

Suggested change
while current != None:
while current:

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

def add_last(self, value):

Choose a reason for hiding this comment

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

👍

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

def visit(self):

Choose a reason for hiding this comment

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

👍

def visit(self):
helper_list = []
current = self.head

while current:
helper_list.append(str(current.value))
current = current.next


print(", ".join(helper_list))

# method to reverse the singly linked list
# note: the nodes should be moved and not just the values in the nodes
# Time Complexity: ?
# Space Complexity: ?
def reverse(self):

Choose a reason for hiding this comment

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

👍

Comment on lines 146 to 147
# 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?

@@ -1,96 +1,165 @@

# Defines a node in the singly linked list
class Node:
from platform import node

Choose a reason for hiding this comment

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

where is this coming from? You've created your own Node class on line 6, so you don't need to import a third-party class

Suggested change
from platform import node

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