If /path/to/file (note: as before, performance and time complexity will largely depend on the structures on the disk and the implementation of the main file system. Ex btrfs, all of this b-tree, ext4 and XFS use H -trees)
Therefore, to move the directory structure to the node leaf (the directory that contains the file), the average case time complexity should be O (logN), in the worst case, O (N), N = there are no directories in the tree. Worst of all, when you have the N-th directory created under N-1, and the N-1-th directory created in N-2, etc. .... to the root directory, which forms a single branch in the tree. Ideally, you do not need to go through all the tree directories from the root if you have the full path.
Then, if your base FS supports directory indexes and hashing, for each search you will need another O (1) to search for the file in the directory. Therefore, O (logN) + O (1), i.e. Ignoring the members of the lower order, it should be only O (logN), where N is the level.
source share