QUESTION 01
What is a tree?
2 marksAnswer
A rooted tree is a hierarchical node structure with one root and one parent for every other node. Its underlying connected undirected graph has no cycle.
QUESTION 01
A rooted tree is a hierarchical node structure with one root and one parent for every other node. Its underlying connected undirected graph has no cycle.
QUESTION 02
Trees represent hierarchical relationships such as directories, expression structure and search organisation.
The root has no parent. Children belong below a parent; siblings share a parent. A leaf has no children. A node’s degree is its number of children. A subtree contains a selected node and its descendants. This material measures height in edges: a leaf has height 0.
A root with two leaf children is perfect, full and complete. A chain is still a binary tree but can have height n - 1. A binary tree is not automatically a binary search tree: the search-order rule must be separately maintained.
A non-empty finite tree with n nodes has n - 1 parent-child edges. Traversing every node is O(n). Algorithms following a root-to-leaf path depend on height h, so the shape affects their work and recursive call depth.
Some texts count height in nodes rather than edges. State the convention before using a numerical formula instead of treating two consistent conventions as contradictory.