Binary trees Flashcards
What is the first node added to a binary tree called?
a) Leaf node
b) Root node
c) Parent node
d) Child node
b) Root node
How many child nodes can a single node in a binary tree have?
a) One
b) Two
c) Three
d) Unlimited
b) Two
What happens when a new node’s value is less than the current node’s value during insertion?
a) It is added to the left of the current node
b) It is added to the right of the current node
c) It is ignored
d) The tree is rebalanced
a) It is added to the left of the current node
What is the name of the class property in the Node class that refers to the left child?
a) leftChild
b) leftNode
c) leftLink
d) childLeft
b) leftNode
What does the insert()
method in the Node class do when encountering a null left or right node?
a) Replaces it with a new node
b) Deletes the current node
c) Ignores the insertion
d) Moves to the parent node
a) Replaces it with a new node
What type of class is the Node class described as, due to its references to itself?
a) Recursive class
b) Cyclic class
c) Self-referential class
d) Linked class
c) Self-referential class
What property does the Tree class use to store the first node of the tree?
a) root
b) firstNode
c) startNode
d) initialNode
a) root
What happens when the insert()
method in the Tree class is called and the root is null?
a) An error occurs
b) A new Node object is assigned to the root
c) The method exits without action
d) The tree is cleared
b) A new Node object is assigned to the root
In the traversal process, what is the first step taken when the current node is null?
a) Print a null value
b) Return from the method
c) Insert a default node
d) Move to the next sibling
b) Return from the method
What is the output of a left-favored traversal of the tree created in the example with values [47, 48, 20, 15, 26, 18]?
a) 15, 18, 20, 26, 47, 48
b) 48, 47, 26, 20, 18, 15
c) 47, 20, 15, 18, 26, 48
d) 26, 15, 20, 18, 48, 47
a) 15, 18, 20, 26, 47, 48
Which method is used to print the tree in descending order?
a) traverse()
b) reverse()
c) traverseFromRoot()
d) reverseFromRoot()
d) reverseFromRoot()
What feature of a binary tree allows it to efficiently store and retrieve ordered data?
a) Self-balancing nodes
b) Branch sorting during insertion
c) Hierarchical memory allocation
d) Contiguous storage
b) Branch sorting during insertion
In a binary tree, what happens if you attempt to insert a value equal to an existing node?
a) The value is ignored
b) The tree duplicates the node
c) The value replaces the existing one
d) The tree rebalances itself
a) The value is ignored
What modification allows a binary tree to return values in descending order during traversal?
a) Adding an extra property to each node
b) Traversing right nodes before left nodes
c) Reversing the root and leaf nodes
d) Adding duplicate nodes
b) Traversing right nodes before left nodes
Which of the following is NOT a common application of binary trees?
a) File systems
b) Email storage
c) Network routing
d) Backtracking algorithms
d) Backtracking algorithms