Trees & Graphs Flashcards
Binary Tree vs. Binary Search Tree
A binary search tree is a binary tree in which every node fits a specific ordering property: a l l l e f t descendents <= n < a l l r i g h t descendents. This must be true for each node n.
Balanced vs. Unbalanced
Complete Binary Trees
A complete binary tree is a binary tree in which every level of the tree is fully filled, except for perhaps the last level. To the extent that the last level is filled, it is filled left to right,
Full Binary Trees
A full binary tree is a binary tree in which every node has either zero or two children. That is, no nodes have only one child.
Perfect Binary Trees
A perfect binary tree is one that is both full and complete. All leaf nodes will be at the same level, and this level has the maximum number of nodes.
Binary Tree Traversal
InOrder (izquierda, raiz, derecha)
PreOrder (raiz, izquierda, derecha)
PostOrder (izquierda, derecha, raiz)
Binary Heaps (Min-Heaps and Max-Heaps)
Min-heap
A min-heap is a complete binary tree (that is, totally filled other than the rightmost elements on the last level) where each node is smaller than its children. The root, therefore, is the minimum element in the tree.
Min-heap operations
insert
extract minimun element
Tries (Prefix Trees)
A trie is a variant of an n-arytree in which characters are stored at each node. Each path down the tree may represent a word.
Graphs
Graph Search
Depth-First Search
Breadth-First Search
Depth-First Search (DFS)
visit a node a and then iterate through each of a’s neighbors.
Breadth-First Search (BFS)
visits each of a’s neighbors before visiting any of their neighbors.