Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with given data.
DSA Python
class Node: def __init__(self, data): self.data = [1] self.next = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'self.next' instead of 'self.data' for storing data.
Assigning 'self' to data attribute.
✗ Incorrect
The new node's data attribute should be set to the given data value.
2fill in blank
mediumComplete the code to check if the linked list is empty before insertion.
DSA Python
def insert_at_end(head, data): new_node = Node(data) if [1] is None: return new_node
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if new_node is None instead of head.
Returning None instead of new_node.
✗ Incorrect
If the head is None, the list is empty, so the new node becomes the head.
3fill in blank
hardFix the error in the loop that finds the last node.
DSA Python
current = head while current.[1] is not None: current = current.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'current.data' instead of 'current.next' in the loop condition.
Using 'current.prev' which does not exist in singly linked list.
✗ Incorrect
To traverse the list, we follow the 'next' pointers until the last node.
4fill in blank
hardFill both blanks to insert the new node at the end of the list.
DSA Python
current = head while current.next is not None: current = current.next current.[1] = [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning data instead of the new node.
Assigning to 'data' attribute instead of 'next'.
✗ Incorrect
The last node's 'next' should point to the new node to insert it at the end.
5fill in blank
hardFill all three blanks to complete the insert_at_end function.
DSA Python
def insert_at_end(head, data): new_node = Node([1]) if [2] is None: return new_node current = head while current.[3] is not None: current = current.next current.next = new_node return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new_node' instead of 'data' when creating the node.
Checking 'new_node' instead of 'head' for empty list.
Using 'data' instead of 'next' in the loop condition.
✗ Incorrect
Create new node with data, check if head is None, then traverse using 'next' to insert at end.