0
0
DSA C++programming~10 mins

Create a Binary Tree Manually in DSA C++ - Interactive Practice

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

Complete the code to declare a pointer to a new TreeNode.

DSA C++
TreeNode* root = new [1](10);
Drag options to blanks, or click blank then click option'
ATreeNode
BNode
CBinaryTree
DTree
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong class name like Node or BinaryTree.
2fill in blank
medium

Complete the code to assign a new left child node with value 5 to root.

DSA C++
root->[1] = new TreeNode(5);
Drag options to blanks, or click blank then click option'
Aright
Bnode
Cchild
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left'.
3fill in blank
hard

Fix the error in the code to assign a right child node with value 15 to root.

DSA C++
root->[1] = new TreeNode(15);
Drag options to blanks, or click blank then click option'
Achild
Bnode
Cright
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right'.
4fill in blank
hard

Fill both blanks to create a left child with value 3 and a right child with value 7 for the left child of root.

DSA C++
root->left->[1] = new TreeNode(3);
root->left->[2] = new TreeNode(7);
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cchild
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right pointers.
5fill in blank
hard

Fill all three blanks to create a right child with value 20 for root, then add left and right children with values 17 and 25 to that node.

DSA C++
root->[1] = new TreeNode(20);
root->right->[2] = new TreeNode(17);
root->right->[3] = new TreeNode(25);
Drag options to blanks, or click blank then click option'
Aleft
Bright
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing left and right pointers in the last two blanks.