Bird
Raised Fist0

What is the time complexity of accessing the nth data block in a file using an inode with direct, single, double, and triple indirect pointers, assuming each indirect block contains M pointers?

medium🪤 Complexity Trap Q5 of Q15
Operating Systems - Inode Structure - File Metadata & Block Pointers
What is the time complexity of accessing the nth data block in a file using an inode with direct, single, double, and triple indirect pointers, assuming each indirect block contains M pointers?
AO(1) for direct blocks; O(1) for indirect blocks due to fixed pointer levels
BO(M) for indirect blocks because each indirect block must be scanned linearly
CO(n) for all blocks because indirect pointers require sequential traversal
DO(1) for direct blocks; O(log_M n) for indirect blocks due to multi-level indirection
Step-by-Step Solution
Solution:
  1. Step 1: Analyze direct block access

    Direct pointers provide immediate access, so O(1).
  2. Step 2: Analyze indirect block access

    Indirect pointers form a tree with branching factor M. Accessing nth block requires traversing up to 3 levels, each indexing into a block of size M, so complexity is O(log_M n).
  3. Step 3: Evaluate other options

    O(1) for direct blocks; O(1) for indirect blocks due to fixed pointer levels incorrectly claims O(1) for indirect blocks ignoring traversal. O(n) for all blocks because indirect pointers require sequential traversal wrongly assumes sequential traversal. O(M) for indirect blocks because each indirect block must be scanned linearly assumes scanning entire indirect block linearly, which is not needed.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Indirect pointers form a tree, so access is logarithmic in M [OK]
Quick Trick: Indirect pointers form a tree, so access is O(log base M) [OK]
Common Mistakes:
MISTAKES
  • Assuming indirect access is O(1) or O(n) due to misunderstanding traversal
Trap Explanation:
PITFALL
  • Candidates confuse fixed pointer levels with constant time or think indirect blocks require scanning all pointers.
Interviewer Note:
CONTEXT
  • Tests understanding of time complexity of multi-level indirect pointer traversal.
Master "Inode Structure - File Metadata & Block Pointers" in Operating Systems

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Operating Systems Quizzes