Binary Search Tree (1) Flashcards
what is a binary search tree
a binary tree in symmetric order
what does the symmetric order property of a binary search tree mean
each node’s key is:
larger than all the keys in its left subtree
smaller than all the keys in its right subtree
what is a leaf of a tree
a node with no children
what is the height of a BST
the maximum number of links from the root to a leaf
what is a level of a BST
the maximum number of nodes from the root to a leaf (includes the root and leaf)
what is the size of a BST
number of nodes in the tree
what is the depth of a BST
number of links from the root to the node
at most, how often does every key appear in a BST
once
every node must have at most how many parents
1
the root has 0
the rest have 1
generally what is the number of levels in a BST
height + 1
in general, how do we search through a BST
currentNode = root
if key we are searching for is less than the currentNode, go left
if the key we are searching for is greater than the currentNode, go right
if the key we are searching for is equal to the key in the currentNode, return
in general, how do we insert into a BST
search for the key we want to insert
if found: do nothing
else: create a new node in the space where the search finished
what does the BST java definition reference
the root node
what are the four values that a BST node is composed on
key
value
left ref
right ref
which of the fields in the node of the BST should be comparable
key
the types key and value in the BST node are …
generic
what does the get function do
return value corresponding to given key
or null if no such key
how does the get function work
while the node is not null
if the key we are looking for is less than the given key go left
if the key we are looking for is greater than the given key go right
else if the keys are equal, return the value of that node
what parameter does the get function take
key
what is the runtime cost of get
1 + depth
so depth as we ignore constant
what is the worst case input for get
asking to get an element that is not in the tree
the get method is the only method that doesn’t use …
recursion
what is the worst possible arrangement of a binary search tree, or any tree
when it looks more like a linked list (each node has either 0 or 1 children)