0
0
DSA Pythonprogramming~10 mins

Traversal and Printing a Linked List 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 move to the next node in the linked list.

DSA Python
current = head
while current is not None:
    print(current.data)
    current = current[1]
Drag options to blanks, or click blank then click option'
A.prev
B.head
C.data
D.next
Attempts:
3 left
💡 Hint
Common Mistakes
Using .prev instead of .next moves backward, which is incorrect for forward traversal.
Using .data instead of .next tries to assign data to current, causing errors.
2fill in blank
medium

Complete the code to start traversal from the first node of the linked list.

DSA Python
def print_list(head):
    current = [1]
    while current is not None:
        print(current.data)
        current = current.next
Drag options to blanks, or click blank then click option'
Ahead
Bhead.next
CNone
Dcurrent
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from head.next skips the first node.
Starting from None means no traversal happens.
3fill in blank
hard

Fix the error in the loop condition to correctly traverse the linked list.

DSA Python
current = head
while current[1]None:
    print(current.data)
    current = current.next
Drag options to blanks, or click blank then click option'
A!=
B=
Cis
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' assigns instead of compares, causing errors.
Using '==' checks equality but loop should continue while not None.
Using 'is' would check if current is None, preventing traversal.
4fill in blank
hard

Fill both blanks to create a dictionary of node data and their positions in the linked list.

DSA Python
positions = {}
index = 0
current = head
while current is not None:
    positions[[1]] = index
    current = [2]
    index += 1
Drag options to blanks, or click blank then click option'
Acurrent.data
Bcurrent.next
Cindex
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using index as key stores position as key, which is incorrect here.
Using head instead of current.next causes infinite loop.
5fill in blank
hard

Fill all three blanks to create a list of node data values from the linked list.

DSA Python
def list_values(head):
    values = []
    current = [1]
    while current is not None:
        values.[2](current.[3])
        current = current.next
    return values
Drag options to blanks, or click blank then click option'
Ahead
Bappend
Cdata
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop removes items instead of adding.
Starting from current instead of head causes error if current undefined.