0
0
Data Structures Theoryknowledge~10 mins

Singly linked list structure in Data Structures Theory - Interactive Code Practice

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

Complete the code to define a node in a singly linked list with a value and a pointer to the next node.

Data Structures Theory
class Node:
    def __init__(self, value):
        self.value = value
        self.[1] = None
Drag options to blanks, or click blank then click option'
Atail
Bprev
Chead
Dnext
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'prev' instead of 'next' for the pointer.
Using 'head' or 'tail' inside the node class.
2fill in blank
medium

Complete the code to create a new node and link it as the next node of the current node.

Data Structures Theory
current_node.next = [1](10)
Drag options to blanks, or click blank then click option'
ANode
BList
CLinkedList
DElement
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the wrong class name to create a node.
Assigning a value directly instead of a node object.
3fill in blank
hard

Fix the error in the code to correctly traverse a singly linked list until the end.

Data Structures Theory
while current_node.[1] is not None:
    current_node = current_node.next
Drag options to blanks, or click blank then click option'
Aprev
Btail
Cnext
Dhead
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'prev' instead of 'next' in the loop condition.
Checking 'head' or 'tail' which are not node pointers.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each node's value to the value of its next node, or None if there is no next node.

Data Structures Theory
value_map = {node.value: node.[1].[2] if node.[1] else None for node in nodes}
Drag options to blanks, or click blank then click option'
Anext
Bvalue
Cprev
Dhead
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'prev' instead of 'next' for the pointer.
Accessing 'head' or 'prev' which do not exist in nodes.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each node's value to the value of the node two steps ahead, or None if not available.

Data Structures Theory
two_ahead_map = {node.[1]: node.[2].[3].value if node.[2] and node.[2].[3] else None for node in nodes}
Drag options to blanks, or click blank then click option'
Avalue
Bnext
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Mixing up 'value' and 'next' in the blanks.
Using 'prev' which does not exist in singly linked lists.