Binary Trees and Binary Search Trees Flashcards
how many children can a node have?
two children(left and right)
what is a node with no children called?
leaf node
a strict binary tree is what…
one that can have either 2 or 0 children
what makes a complete binary tree?
a tree where all levels are filled except possible the last and all nodes are as left as possible
what is the maximum number of nodes for every level i?
i = 2^i
what is the max # of nodes in a binary tree with height h
2^(h+1) -1
what is the perfect height of a binary tree given nodes?
h = log base 2 (n+1) -1
when do you have a balanced binary tree?
when the difference between the heights of the left and right subtrees for every node is not more than k(mostly 1)
what is the height of a binary tree?
the # of edges in longest path from root to a leaf
what is the height of an empty tree?
-1
what is the height of a tree with 1 node?
0
what is a binary search tree?
a binary tree in which for each node, the value of all the nodes in the left subtree is lesser or equal to and the value of all the nodes in the right subtree is greater.
how do you create the node class for a BST?
protected static class Node {
public E data; // The information stored in this node.
public Node left; //Reference to the left child
public Node right; //Reference to the right child.
public Node(E data) { this.data = data; left = null; right = null; }
how do you initiate the root node of BT?
protected Node root;
how do you set the root node of a class to be null?
public BinaryTree(){ //BinaryTree is the name of the class root=null; }