This project implements a basic Linux File System using Binary Search Trees. The file system utilizes Binary Search Trees to efficiently store and manage directories and files. Each directory and file is organized within the tree structure, enabling operations such as printing directory contents in a lexicographic order and searching for files using the find
command.
- Initializes the root directory and allocates memory for it.
- Creates a file node within a directory.
- Creates a directory node within a directory.
- Check if a file or directory already exists in the tree.
- Traverse the tree in an SRD (in-order) manner to print file and directory names in lexicographic order.
- Lists the contents of the current directory.
- Creates a file within the current directory.
- Creates a directory within the current directory.
- Removes a directory within the current directory.
- Prints the current working directory.
- Changes the current working directory.
- Removes a file within the current directory.
- Searches for a file within the file system.
- Initializes the root directory and reads user instructions to perform file system operations.
The complexity of various operations in the file system implemented using Binary Search Trees is as follows:
-
Insertion of a file or directory: O(log n), where n is the number of files or directories in the tree. This is because Binary Search Trees provide efficient insertion by maintaining the tree structure.
-
Searching for a file or directory using
find
: O(log n) on average. Similar to insertion, searching in a Binary Search Tree is efficient due to its structure. -
Listing directory contents (
ls
): O(n), where n is the number of files or directories in the current directory. This is because listing contents involves traversing all elements in the directory. -
Changing directory (
cd
): O(log n), where n is the number of directories in the file system. -
Removing a file or directory: O(log n), where n is the number of files or directories in the tree. Removal involves finding the node to delete, which is efficient in a Binary Search Tree.