w1d5 Flashcards
What is a tree comprised of?
Nodes
What is the top-level node called?
The root; it has children but no parents
What are bottom level nodes called?
The leaves; they have a parent but no children.
What is the maximum number of parents a node can have?
1
What is the difference between DFS and BFS?
Depth-first search uses a stack: Each node has its children pushed onto the stack, then each of those nodes has their children pushed on the stack. When a leaf is reached, the leaf is popped off the stack until a node with another child is found. A DFS algorithm is recursive.
BFS uses a queue; each node has its children added to the end of the queue, and nodes are shifted off the front of the queue and evaluated. A BFS algorithm utilized an iterative loop.