Answered step by step
Verified Expert Solution
Question
1 Approved Answer
class Node: Do not modify this class o o o Attributes: o value: Value stored in a Node next: Reference to the following Node (May
class Node: Do not modify this class o o o Attributes: o value: Value stored in a Node next: Reference to the following Node (May be None) init (self, value: T, next: Node = None) -> None: o This function initializes a node with a given value and next reference, pointing to the next Node in the list. self.value - the value of the Node. self.next - the next Node in the list, default value is None repr (self) -> str: o A node is represented in string form as 'value'. str (self) -> str: o A node is represented in string form as 'value'. Use str (node) to make it a string. eq_(self, other: Node) -> bool: o This function compares two Nodes. o other - the right-hand operand of the ==" o Returns either True or False class RecursiveSinglyLinkedList: Do not modify the following attributes/methods O Attributes: o head: The first Node in the linked list (May be None) init (self) -> None: o This function initializes a RecursivelySinglyLinkedList repr__(self) -> str: A string representation of the list. o For this to work, you must have completed to_string eq_(self, other: Node) -> bool: This function compares two Recursive SinglyLinkLists. o other - the right-hand operand of the ==" o Returns either True or False o remove_all (self, value: T) -> None : o Remove all nodes in the list with the given value o If the value doesn't exist, do not change the linked list o Must call remove_all_inner o Time complexity: O(n) remove_all_inner (curr: Node) -> Node : This is a helper function for remove_all o Remove all nodes in the list with the given value (from remove_all) starting at head curr o If the value doesn't exist, do not change the linked list o This function must be recursive Time complexity: O(n) search (self, value: T) -> bool: o Looks for value in the list o Returns True if the value is in the list and False if it is not in the list o Must call search inner o Time complexity: Oln) search_inner (curr: Node) -> bool: This is a helper function for search o Looks for value (from search) in the list starting with head curr o Returns True if the value is in the list and False if it is not in the list o This function must be recursive o Time complexity O(n) count (self, value: T) -> int: o Counts and returns how many times the given value occurs in the list Must call count_inner o Time complexity: O(n) count_inner (curr: Node) -> int: o This is a helper function for count o Counts and returns how many times the given value (from count) occurs in the list starting at head curr o This function must be recursive o Time complexity: O(n) reverse (self, curr: Node) -> Node: o Given a list starting with head curr, reverse this list. o Return the head of the reversed list. o This function must be recursive o Time complexity: O(n) . o class Node: Do not modify this class o o o Attributes: o value: Value stored in a Node next: Reference to the following Node (May be None) init (self, value: T, next: Node = None) -> None: o This function initializes a node with a given value and next reference, pointing to the next Node in the list. self.value - the value of the Node. self.next - the next Node in the list, default value is None repr (self) -> str: o A node is represented in string form as 'value'. str (self) -> str: o A node is represented in string form as 'value'. Use str (node) to make it a string. eq_(self, other: Node) -> bool: o This function compares two Nodes. o other - the right-hand operand of the ==" o Returns either True or False class RecursiveSinglyLinkedList: Do not modify the following attributes/methods O Attributes: o head: The first Node in the linked list (May be None) init (self) -> None: o This function initializes a RecursivelySinglyLinkedList repr__(self) -> str: A string representation of the list. o For this to work, you must have completed to_string eq_(self, other: Node) -> bool: This function compares two Recursive SinglyLinkLists. o other - the right-hand operand of the ==" o Returns either True or False o remove_all (self, value: T) -> None : o Remove all nodes in the list with the given value o If the value doesn't exist, do not change the linked list o Must call remove_all_inner o Time complexity: O(n) remove_all_inner (curr: Node) -> Node : This is a helper function for remove_all o Remove all nodes in the list with the given value (from remove_all) starting at head curr o If the value doesn't exist, do not change the linked list o This function must be recursive Time complexity: O(n) search (self, value: T) -> bool: o Looks for value in the list o Returns True if the value is in the list and False if it is not in the list o Must call search inner o Time complexity: Oln) search_inner (curr: Node) -> bool: This is a helper function for search o Looks for value (from search) in the list starting with head curr o Returns True if the value is in the list and False if it is not in the list o This function must be recursive o Time complexity O(n) count (self, value: T) -> int: o Counts and returns how many times the given value occurs in the list Must call count_inner o Time complexity: O(n) count_inner (curr: Node) -> int: o This is a helper function for count o Counts and returns how many times the given value (from count) occurs in the list starting at head curr o This function must be recursive o Time complexity: O(n) reverse (self, curr: Node) -> Node: o Given a list starting with head curr, reverse this list. o Return the head of the reversed list. o This function must be recursive o Time complexity: O(n) . o
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started