Tree Data Structures
How do you calculate a level of a node?
1 + (the number of connections between the node and the root)
Self-balancing binary search tree
A binary search that automatically keeps the tree balanced after insertions and deletions so that the maximum height is logarithmic
Complete binary tree
A binary tree in which every level of the tree is fully filled, except maybe the last level in that it is filled from left to right
Perfect binary tree
A binary tree that is both full and complete All leaf nodes will be at the same level, and this level has the maximum number of nodes
Full binary tree
A binary tree which every node has either 0 or 2 children
Siblings
A group of nodes with the same parent
Ancestor
A node reachable by repeated proceeding from child to parent
Descendent
A node reachable by repeated proceeding from parent to child
Branch / Internal Node
A node with at least one child
Binary search tree
A rooted binary tree which maintains the binary search property that the value in each node must be greater than or equal to any value stored in the left sub-tree, and less than or equal to any value stored in the right sub-tree
Path
A sequence of nodes and edges connecting a node with a descendent
Binary Tree
A tree in which each node has up to 2 children
Rooted tree
A tree in which one vertex has been designated the "root"
Null or empty tree
A tree with no nodes
Free tree
A tree without any designated root
Tree
Abstract data type that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node. A data structure made up of nodes and edges without having any cycles
Can a tree contain any data type or only integers?
Any data type
T/F Order among sibling does not matter in rooted trees
F
How is the height of tree calculated?
Height of its root node
Where is the minimum element in a Binary Search Tree?
In the leftmost descendent of the root
Where is the maximum element in a Binary Search Tree?
In the rightmost descendent of the root
Can a binary tree be considered "full" if some nodes have only 1 child?
No Must be either only 0 or 2 children
Can a tree contain cycles?
No There are no links back to their parent nodes
Are all trees binary?
No There are such things as ternary trees or 5-ary trees
Child
Node directly connected to another node away from the Root
Parent
Node directly connected to another node toward the Root
Leaf / External Node
Node with NO children
Depth of a node
Number of edges from the tree's root node to the node
Time complexity for searching for a key in a binary search tree Why?
O(h) 'h' = the height of the tree You search by looking at either the left or right subtree depending on if the value is less than or greater than the root recursively
Rooted binary tree
Recursively defined as either: - Empty - Consisting of a node called the "root" - Together with 2 rooted binary trees called the left and right subtrees
Examples of self-balancing BSTs
Red-black trees, AVL trees
Edge
The connection between one node and another
Balanced tree
The left and right subtrees of every node differ by no more than 1 Also balanced enough to ensure O( log n) insertion and search
Binary search requires that we have fast access to what 2 elements?
The median elements above and below the given node Which would need a linked-list with 2 pointers per node
How do you find the height of a node?
The number of edges on the longest path between that node and a leaf
Degree
The number of subtrees of a node
What are Binary Search Trees used for?
To construct more abstract data structures such as sets and associative arrays
Root
Top node in a tree