Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start Morris traversal by setting current to root.
DSA Javascript
let current = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting current to null or head instead of root.
✗ Incorrect
We start Morris traversal from the root node, so current should be set to root.
2fill in blank
mediumComplete the condition to check if current has a left child.
DSA Javascript
while (current !== null) { if (current.[1] === null) { // Process current node } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking current.right instead of current.left.
✗ Incorrect
We check if current.left is null to decide if we can process current or need to find predecessor.
3fill in blank
hardFix the error in finding the inorder predecessor by completing the loop condition.
DSA Javascript
let predecessor = current.left; while (predecessor.[1] !== null && predecessor.[2] !== current) { predecessor = predecessor.right; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using predecessor.left instead of predecessor.right.
✗ Incorrect
The inorder predecessor is found by moving to the rightmost node in the left subtree, so we check predecessor.right.
4fill in blank
hardFill both blanks to create or remove the temporary thread in Morris traversal.
DSA Javascript
if (predecessor.[1] === null) { predecessor.[2] = current; current = current.left; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using left or parent instead of right for the thread pointer.
✗ Incorrect
We create a temporary thread by setting predecessor.right to current, so both blanks are 'right'.
5fill in blank
hardFill all three blanks to correctly remove the temporary thread and move current in Morris traversal.
DSA Javascript
else { predecessor.[1] = null; console.log(current.[2]); current = current.[3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Removing thread from left pointer or printing current.left.
✗ Incorrect
We remove the thread by setting predecessor.right to null, print current.value, and move current to current.right.