Data Structures Flashcards
What is a graph
Any collection of nodes and their pointers to other nodes. Linked lists and trees are both types of graphs
What is a binary tree
A binary tree is a type of tree. It is a collection of nodes. Every node has between 0 to 2 children, and every node except the root has exactly one parent.
In a tree, what is a root node
The root node is the node at the “top” of the tree. Every node in the tree is accessible starting from the root node. The root node has no parents
In a tree, what is a parent and what is a child
If you have a node A
with an edge to a node B
, so A -> B
, we call A
the parent of node B
, and node B
a child of node A
.
In a tree, what is a leaf node
A leaf node is a node that has no children
In a tree, what is the depth of a node
The depth of a node is how far it is from the root node. The root has a depth of 0
. Every child has a depth of parentsDepth + 1
, so the root’s children have a depth of 1
, their children have a depth of 2
, and so on.
in a tree, what is a subtree
A subtree of a tree is a node and all of it’s descendants. A subtree is a valid tree where the chose node is the root of the subtree