ディレクトリ又はファイルがノードに対応する木構造で表現できるファイルシステムがある。ルートディレクトリを根として図のように表現したとき,中間ノードである節及び末端ノードである葉に対応するものの組合せとして,最も適切なものはどれか。ここで,空のディレクトリを許すものとする。 - 根(最上部のノード) - 葉(根の左の子,末端ノード) - 節(根の右の子,中間ノード) - 葉(節の左の子,末端ノード) - 葉(節の右の子,末端ノード)
令和4年度 ITパスポート試験 問90
This question's explanation and your answers so far.
問 90
- ア
正解 An internal node (a middle node) is a node that has children. In a file system, only a directory can store other elements (files or directories) inside it and hang child nodes below it, so the internal node must correspond to a “directory.” On the other hand, a leaf (a terminal node) is a node that has no children. A file cannot store anything inside it and is always a terminal, so it is a leaf; moreover, because of the condition “empty directories are allowed,” an empty directory with no contents also has no children and can be a leaf. Therefore the leaf corresponds to a “directory or file.” This combination is ア, which is correct.
Incorrectイ
“Internal node = directory” is correct, but limiting the leaf to only “file” is wrong. Since empty directories are allowed, an empty directory with no children can also be a leaf, so the leaf cannot be limited to files.
Incorrectウ
Treating the internal node as a “file” is wrong. A file cannot have child nodes and can only be a terminal, so it cannot be a middle node (internal node) that has children. The internal node must be a directory.
Incorrectエ
Treating the internal node as a “file” is wrong (a file has no children and cannot be an internal node). Furthermore, limiting the leaf to only “directory” is also wrong, since a file likewise has no children and becomes a leaf. The correspondence between internal node and leaf is reversed, so it is doubly wrong.
- Tree structure terminology: a node with children is an internal node (middle node), and a node without children is a leaf (terminal node). In a file system, only a directory can hang children below it, so the internal node can only be a directory.
- The condition “empty directories are allowed” is the key. A file is always a leaf, but an empty directory with no contents also has no children and can be a leaf, so the leaf is a “directory or file.”