0
0
Data Structures Theoryknowledge~10 mins

Inorder traversal gives sorted order 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 print the nodes of a binary search tree in sorted order using inorder traversal.

Data Structures Theory
def inorder_traversal(node):
    if node is not None:
        inorder_traversal(node.left)
        print(node[1])
        inorder_traversal(node.right)
Drag options to blanks, or click blank then click option'
A.value
B.val
C.key
D.data
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like .val or .key which may not exist.
Printing the node object directly instead of its value.
2fill in blank
medium

Complete the code to collect the inorder traversal result in a list instead of printing.

Data Structures Theory
def inorder_collect(node, result):
    if node is not None:
        inorder_collect(node.left, result)
        result.append(node[1])
        inorder_collect(node.right, result)
Drag options to blanks, or click blank then click option'
A.val
B.value
C.data
D.key
Attempts:
3 left
💡 Hint
Common Mistakes
Appending the node object instead of its value.
Using wrong attribute names causing errors.
3fill in blank
hard

Fix the error in the inorder traversal code that causes incorrect order by completing the blank.

Data Structures Theory
def inorder_traversal(node):
    if node is not None:
        inorder_traversal(node.right)
        print(node[1])
        inorder_traversal(node.left)
Drag options to blanks, or click blank then click option'
A.value
B.val
C.data
D.key
Attempts:
3 left
💡 Hint
Common Mistakes
Visiting right subtree before left causing descending order output.
Using wrong attribute names for node data.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each node's value to its depth during inorder traversal.

Data Structures Theory
depth_map = {node[1]: depth for node, depth in nodes if node[2]
Drag options to blanks, or click blank then click option'
A.value
Bis not None
C!= None
D.val
Attempts:
3 left
💡 Hint
Common Mistakes
Using != None instead of is not None which is less preferred.
Using wrong attribute names for node values.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that stores node values as keys and their depths as values, filtering only nodes with values greater than 10.

Data Structures Theory
depth_map = {node[1]: depth for node, depth in nodes if node[2] [3] 10}
Drag options to blanks, or click blank then click option'
A.value
Bvalue
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent attribute names in keys and condition.
Using wrong comparison operators like >= when only greater than is needed.