0
0
DSA Pythonprogramming~10 mins

Why Linked List Exists and What Problem It Solves in DSA Python - Test Your Knowledge

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

Complete the code to create a linked list node with a value.

DSA Python
class Node:
    def __init__(self, data):
        self.data = data
        self.[1] = None
Drag options to blanks, or click blank then click option'
Anext
Bprev
Chead
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for a singly linked list node.
2fill in blank
medium

Complete the code to add a new node at the beginning of the linked list.

DSA Python
def add_at_head(head, data):
    new_node = Node(data)
    new_node.[1] = head
    return new_node
Drag options to blanks, or click blank then click option'
Ahead
Bprev
Cnext
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'prev' instead of 'next' causes errors in singly linked lists.
3fill in blank
hard

Fix the error in the code to traverse and print all node values in the linked list.

DSA Python
def print_list(head):
    current = head
    while current is not None:
        print(current.data)
        current = current.[1]
Drag options to blanks, or click blank then click option'
Anext
Bprev
Chead
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' or 'head' instead of 'next' causes infinite loops or errors.
4fill in blank
hard

Complete the code to add a new node at the end of the linked list.

DSA Python
def add_at_tail(head, data):
    new_node = Node(data)
    if head is None:
        return new_node
    current = head
    while current.[1] is not None:
        current = current.next
    current.[2] = new_node
    return head
Drag options to blanks, or click blank then click option'
Anext
Bprev
Chead
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' or assuming a 'tail' pointer in a basic singly linked list.
5fill in blank
hard

Complete the code to reverse the linked list iteratively.

DSA Python
def reverse(head):
    prev = None
    curr = head
    while curr is not None:
        next_temp = curr.[1]
        curr.[2] = prev
        prev = curr
        curr = next_temp
    return prev
Drag options to blanks, or click blank then click option'
Anext
Bprev
Chead
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' for saving next_temp or forgetting to save it causes data loss.