Trees, Binary Trees, BSTs Flashcards
What is the “depth” of a node x. Depth is always relative to…
Length of path from the root of the TREE to that node. Depth is always relative to the root of the tree
The depth of a node x is also its…
level in the tree
Siblings or cousins of a tree have the same…(starts with a d)
depth
What is the height of a node x
Height of any node x in a tree is the number of edges of the longest path from that node to a leaf node.
What is the height of any leaf node?
0
What is the height of a tree?
Height of root node
What is the only requirement for a binary tree
All nodes can have at most two children
What is a full binary tree?
a binary tree in which every node has two or zero children Another definition is: a binary tree in which every interior node has exactly two children
What is a complete binary tree?
A binary tree where all levels except possibly the last level are completely filled and as far left as possible
What is the max number of leaves you can have in a complete binary tree?
2^h where h is the height of the root
What is a perfect binary tree?
A binary tree where all levels are completely filled
True or false: a perfect binary tree is also a complete tree
True
How many nodes are there in a perfect tree with height h?
2^(h+1)-1 or 2^(levels in the tree) - 1
What is the height of a perfect binary tree with n nodes?
h = log_2(n+1) - 1
What is the equation for the height of a complete binary tree?
floor of log_2(n) where n = # of nodes
Time complexity of inserting, searching, and removing an element is proportional to its _____ in a BST. Thus, time complexity can be said to be O of ______ in terms of the tree’s _____
tree height. h, height
What is the minimum possible height in a BST?
h = floor of log_2(n)