0
0
DSA Pythonprogramming~10 mins

Insert at End Tail Insert in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ANode
Bself
Cnext
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'self.next' instead of 'self.data' for storing data.
Assigning 'self' to data attribute.
2fill in blank
medium

Complete 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'
Adata
Bnew_node
Chead
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if new_node is None instead of head.
Returning None instead of new_node.
3fill in blank
hard

Fix 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'
Anext
Bdata
Chead
Dprev
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.
4fill in blank
hard

Fill 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'
Anext
Bdata
Cnew_node
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning data instead of the new node.
Assigning to 'data' attribute instead of 'next'.
5fill in blank
hard

Fill 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'
Adata
Bhead
Cnext
Dnew_node
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.