-
Notifications
You must be signed in to change notification settings - Fork 87
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
base: master
Are you sure you want to change the base?
Makhabat - Cedar #62
Conversation
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
def get_first(self): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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:
while current != None: | |
while current: |
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def length(self): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while current != None: | |
while current: |
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
|
||
def add_last(self, value): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: ? | ||
# Space Complexity: ? |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
from platform import node |
No description provided.