0
0
Data Structures Theoryknowledge~10 mins

Doubly linked list 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 doubly linked list with pointers to both previous and next nodes.

Data Structures Theory
class Node:
    def __init__(self, data):
        self.data = data
        self.prev = [1]
        self.next = None
Drag options to blanks, or click blank then click option'
ANone
Bself
C0
Ddata
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Setting prev to self causes circular reference.
Using data or 0 for prev is incorrect.
2fill in blank
medium

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

Data Structures Theory
def insert_at_head(head, data):
    new_node = Node(data)
    new_node.next = head
    if head is not None:
        head.[1] = new_node
    return new_node
Drag options to blanks, or click blank then click option'
Anext
Bdata
Cprev
Dhead
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Setting next instead of prev causes incorrect links.
Not updating the old head's prev pointer breaks the list.
3fill in blank
hard

Fix the error in the code that deletes a node from a doubly linked list.

Data Structures Theory
def delete_node(node):
    if node.prev is not None:
        node.prev.next = node.next
    if node.next is not None:
        node.next.[1] = node.prev
Drag options to blanks, or click blank then click option'
Anext
Bnode
Cdata
Dprev
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Setting next instead of prev causes broken backward links.
Not updating pointers leads to dangling references.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps node data to their next node's data if the next node exists.

Data Structures Theory
{node.data: node.next[1] for node in nodes if node.next is not [2]
Drag options to blanks, or click blank then click option'
A.data
BNone
CTrue
DFalse
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'True' or 'False' instead of None in the condition.
Forgetting to access the data attribute of the next node.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase node data to the previous node's data if the previous node exists and its data is greater than 10.

Data Structures Theory
{node.data[1]: node.prev[2] for node in nodes if node.prev is not None and node.prev.data [3] 10}
Drag options to blanks, or click blank then click option'
A.upper()
B.data
C>
D<
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using '<' instead of '>' in the comparison.
Not converting node data to uppercase.
Forgetting to access the previous node's data attribute.