- Home
- Interview Questions
- Data structures and Algorithms
51.
Describe the inorder traversal algorithm.
Inorder traversal gets its name from the fact that it visits the root in between visiting the left and right subtrees. The steps are the following:
- traverse the left subtree
- visit the root
- traverse the right subtree
52.
What is the difference between a max-heap and a min-heap?
- A max-heap respects the property that if B is a child node of A, then key( A) >= key(B) - the greatest key is always in the root node
- A min-heap respects the property that if B is a child node of A, then key( A) <= key(B) - the smallest key is always in the root node
53.
What is a heap?
A heap is a specialized tree-based data structure that satisfies the heap property:
if B is a child node of A, then key(A) >= key(B). This implies that an element with the greatest key is always in the root node.
54.
Describe the breadth-first traversal algorithm.
The breadth-first traversal of a tree visits the nodes in the order of their depth in the tree. Breadth-first traversal first visits all the nodes at depth zero (i.e. the root), then all the nodes at depth one, and so on. At each depth the nodes are visited from left to right.
55.
Describe the postorder traversal algorithm.
Postorder traversal gets its name from the fact that it visits the root last. The steps are the following:
- traverse the left subtree
- traverse the right subtree
- visit the root