Trees and Graphs Flashcards
1
Q
Graph
A
- node-based data structure
- a series of nodes that each may or may not have child nodes. These nodes may direct to each other in a circular fashion, and they may be bi-directional
2
Q
Breath first search (BFS)
A
-visits every neighbor of a node before visiting its children
3
Q
Depth first search (DFS)
A
- search each complete branch before moving to the next one
- covers searches through every available child node before moving to a neighbor
4
Q
Recursive
A
calls itself with new data until its done
5
Q
Trees
A
- a subtype of graph
- cannot contain cycles
- nodes without children are called “leaf nodes”
- may be restricted to n children per node, like a Binary Tree (n=2)
6
Q
Binary search tree
A
- a sorted binary tree
- left hand children are less or equal to root node and right hand children are greater than that node
- searching happens in O(logn) time
7
Q
Balanced vs Complete Tree vs Full
A
- balanced when the number of nodes to either side of the root are roughly equal
- complete when every non-leaf node has two children (except the rightmost node)
- full where every Level has exactly 0 or 2 children
- perfect tree is both full and complete
8
Q
Tree Traversal
A
- Inorder
- preorder
- post-order