0
0
DSA Pythonprogramming~10 mins

Linked List vs Array When to Choose Which in DSA Python - Interactive Comparison Practice

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

Complete the code to create an array with 5 elements.

DSA Python
arr = [[1]]
Drag options to blanks, or click blank then click option'
A1, 2, 3, 4, 5
B[]
Crange(5)
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using range(5) directly creates a range object, not a list.
Using empty brackets creates an empty list.
2fill in blank
medium

Complete the code to add a new node with value 10 at the start of a linked list.

DSA Python
new_node = Node(10)
new_node.next = [1]
head = new_node
Drag options to blanks, or click blank then click option'
Anew_node
Bhead
CNone
Dhead.next
Attempts:
3 left
💡 Hint
Common Mistakes
Setting new_node.next to None breaks the list.
Using head.next instead of head causes errors.
3fill in blank
hard

Fix the error in the code to remove the last element from an array.

DSA Python
arr = [1, 2, 3, 4, 5]
arr.[1]()
Drag options to blanks, or click blank then click option'
Apop()
Bremove(5)
Cpop(0)
Ddelete()
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove(5) removes the first occurrence of 5 but is less efficient.
delete() is not a valid list method.
4fill in blank
hard

Fill both blanks to traverse a linked list and print each node's value.

DSA Python
current = head
while current [1] None:
    print(current.[2])
    current = current.next
Drag options to blanks, or click blank then click option'
Ais not
Bvalue
Cval
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'is not' for None check.
Using 'val' instead of 'value' if the attribute is named 'value'.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.

DSA Python
{ [1]: [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not filtering words by length correctly.