MOD 7_ZYBOOKS 9_BINARY SEARCH TREES Flashcards
(45 cards)
What is a binary tree?
What is a left child and a right child?
In a list, each node has up to one successor. In a binary tree, each node has up to two children, known as a left child and a right child. “Binary” means two, referring to the two children.
Provide definitions for:
- Leaf
- Internal node
- Parent, ancestors
- Root
Provide definitions for:
- Edge
- Depth
- Level
- Height
What are the 3 special types of binary trees?
VIEW: Special types of binary trees: full, complete, perfect
Trees are commonly used to represent ____ data. A tree can represent files and directories in a file system, since a file system is a hierarchy.
Hierarchical
What is Binary Space Partitioning (BSP)?
What is a BSP tree?
Binary space partitioning (BSP) is a technique of repeatedly separating a region of space into 2 parts and cataloging objects contained within the regions. A BSP tree is a binary tree used to store information for binary space partitioning. Each node in a BSP tree contains information about a region of space and which objects are contained in the region.
In graphics applications, a ____ tree can be used to store all objects in a multidimensional world. It can then be used to efficiently determine which objects must be rendered on screen.
The viewer’s position in space is used to perform a lookup within this tree. The lookup quickly eliminates a large number of objects that are not visible and therefore should not be rendered.
BSP
VIEW: Using trees to store collections
What is a Binary Search Tree (BST)?
An especially useful form of binary tree is a binary search tree (BST), which has an ordering property that any node’s left subtree keys ≤ the node’s key, and the right subtree’s keys ≥ the node’s key. That property enables fast searching for an item, as will be shown later.
VIEW: BST ordering property: For three nodes, left child is less-than-or-equal-to parent, parent is less-than-or-equal-to right child. For more nodes, all keys in subtrees must satisfy the property, for every node.
To ____ nodes means to find a node with a desired key, if such a node exists. A ____ may yield faster searches than a list - this starts by visiting the root node (which is the first currentNode below).
Search
BST
With a BST, if a ____ to be visited doesn’t exist, the desired node does not exist. With this approach, only a small fraction of nodes need be compared.
Child
VIEW: BST search runtime
VIEW: Minimum binary tree heights for N nodes are equivalent to log_2(N)
What is a BST node successor and predecessor?
A BST defines an ordering among nodes, from smallest to largest. A BST node’s successor is the node that comes after in the BST ordering, so in A B C, A’s successor is B, and B’s successor is C. A BST node’s predecessor is the node that comes before in the BST ordering.
If a node has a right subtree, the node’s successor is that right subtree’s leftmost child: Starting from the right subtree’s root, follow left children until reaching a node with no left child (may be that subtree’s root itself). If a node doesn’t have a right subtree, the node’s successor is the first ancestor having this node in a left subtree. Another section provides an algorithm for printing a BST’s nodes in order.
Given a key, a ____ algorithm returns the first node found matching that key, or returns ____ if a matching node is not found.
A simple ____ search algorithm checks the ____ node (initially the tree’s root), returning that node as a match, else assigning that node with the left (if key is less) or right (if key is greater) child and repeating. If such a child is null, the algorithm returns null (matching node not found).
Search, null
BST, current
How does a BST insert operation work?
VIEW: BST insert algorithm complexity
How does a BST remove operation work?
The algorithm performs which 3 sub-algorithms?
VIEW: BST remove algorithm.
VIEW: BST remove algorithm complexity
What is a tree traversal algorithm?
What is an inorder traversal?
A tree traversal algorithm visits all nodes in the tree once and performs an operation on each node. An inorder traversal visits all nodes in a BST from smallest to largest, which is useful for example to print the tree’s nodes in sorted order. Starting from the root, the algorithm recursively prints the left subtree, the current node, and the right subtree.
VIEW: BST inorder traversal algorithm