5 BINARY SEARCH TREES Flashcards
What is a binary search tree?
A dynamic data structure that supports efficient addition, removal, and searching of elements.
What are the key advantages of binary search trees over sorted arrays?
Efficient addition and removal of elements in addition to searches.
What is the structure of a binary search tree?
A hierarchical data structure composed of nodes, where each node has a value and up to two pointers to child nodes.
What are internal nodes and leaf nodes in a binary search tree?
Internal nodes have at least one child, while leaf nodes do not have any children.
What minimal information does a binary search tree node contain?
A value (or key), pointers to two child nodes, and an optional pointer to the parent node.
How is the binary search tree property defined?
For any node N, the value of any node in N’s left subtree is less than N’s value, and the value of any node in N’s right subtree is greater than N’s value.
What is the implication of the binary search tree property on node values?
It restricts the binary search tree to contain unique values.
True or False: Binary search trees can be defined to allow duplicate values.
True.
What is the role of pointers in a binary search tree?
Pointers link nodes to their children and parents, allowing traversal through the tree structure.
How do we search for a value in a binary search tree?
By walking down from the root node and comparing the current node’s value with the target value.
What happens if the target value is less than the current node’s value during a search?
The search progresses to the left subtree.
What happens if the target value is greater than the current node’s value during a search?
The search progresses to the right subtree.
What are the two approaches to implement a search in a binary search tree?
Iterative and recursive approaches.
What does the recursive search function return if the target value is not found?
Null.
In the context of a binary search tree, what does a dead end indicate?
A node that does not match the target value and does not have a child in the correct direction.
Describe the iterative search function for a binary search tree.
It uses a WHILE loop to traverse down the tree, checking values and reassigning the current node until the target is found or a dead end is reached.
What is the computational cost of searching in a binary search tree?
Proportional to the depth of the target value in the tree.
How does the structure of a binary search tree affect search efficiency?
Minimizing the tree’s depth increases search efficiency.
What is the primary concern when comparing binary search trees to sorted arrays?
Whether the added complexity and overhead of pointers are worth it compared to a single binary search on a sorted array.
Fill in the blank: A binary search tree starts at a single _______ node.
root
What is the purpose of auxiliary data in a binary search tree node?
To store additional information related to the node’s value, enhancing the data structure’s utility.
Why might a sorted array be preferable over a tree for a single search?
Building a tree is more expensive than a single linear scan.
What is a key advantage of using binary search trees in dynamic data environments?
Binary search trees allow efficient addition and removal of data points.
What is the first step when searching for a node in a binary search tree?
Start at the root node.