Binary Trees Flashcards
Binary tree are both
1) Recursive
2) Ordered
Depth three items
1) inoreder
2) perorder
3) Postorder
Killer feature
Searching
Killer feature
Searching - 1/2 ‘s the search each pass
Binary Tree - How is data stored
Nodes (like leafs on a tree)
Binary Tree - How is data stored
Nodes (like leafs on a tree) with keys
Binary tree - Describe a full binary tree
Tree with zero or two children (no single children)
Binary tree - Describe a balanced binary tree
It has the minimum possible height
Binary tree - Breadth first
Search across the tree first (think the data is somewhere near the top)
What type of algorithms use Breadth first
shortest pass
Binary tree - depth First
Think the data is deep deep down the tree
example: maze problems
Binary Search Tree (BST) - how are nodes(keys) sorted
Nodes keys are sorted top to Bottom all the nodes left of the parent are smaller then the parent, And all the nodes right to the parent are larger 5 / \ 3 7 / \ / \ 2 4 6 8
Also every level search eliminates half of the data
Binary Search Tree (BST) search find 4 (how many hops)
5 / \ 3 7 / \ / \ 2 4 6 8
5 4<> ? / \ 4<> ? 3 7 / \ / \ 2 4 6 8
three hops
Binary insert - How to insert a (2)
5 / 3
1) start at 5 (it is less than 5 so it goes on the left
2) Is it great then or less then 3 (it is less then so we go down)
3) so Insert it to the empty node below 3
5 / 3 / 2
Binary insert - How to insert a (4)
5 / 3
5 / 3 / \ 2 4
Four is greater then three so go to right node