Part A — Design an in-memory hierarchical file system.
Requirements:
-
Support operations: ls(path), mkdir(path), createFile(path, content), appendToFile(path, content), readFile(path).
-
Paths are absolute UNIX-style. Root is "/". No trailing slash except for "/".
-
Error handling: if any intermediate subfolder in the path does not exist, return an error and do not create missing directories. For example, mkdir("/a/b") should error if "/a" is missing; createFile("/a/b/c.txt", ...) should error if "/a/b" is missing.
-
ls(path): if path is a directory, return its child names in lexicographic order; if path is a file, return [fileName].
-
Assume no permissions or concurrency. Handle invalid inputs (empty segment, duplicate slashes). Scale to a large number of paths efficiently.
Tasks:
-
Specify data structures and APIs.
-
Implement the operations.
-
Analyze time and space complexity per operation and overall.
-
Explain edge cases around the root directory and invalid paths.
Part B — Implement a fixed-size circular queue.
Requirements:
-
Constructor(capacity).
-
Operations: enQueue(x): bool, deQueue(): bool, Front(): optional
<int>
, Rear(): optional
<int>
, isEmpty(): bool, isFull(): bool.
-
All operations must be O(
-
time and O(capacity) space.
Tasks:
-
Implement the queue.
-
Explain your choice of data structure (e.g., doubly linked list vs circular array) and trade-offs.
-
Prove correctness and analyze complexity.