I have the following question from an interview test (it should be short and easy): I need to create a file system. I need to create an object file, let it have an identifier. I have to create a directory that has an identifier, and I can add some auxiliary data. I can not use any java.util.Collections, and I need to create all the dast myself. the problem is to find the optimal implementation of the directory hierarchy. functions that I need to implement: addDirectory (parentDirectoryId) removeDirectory (DirectoryId), printAll () - logically prints the hierarchy of folders and files.
I thought you had the root directories of the directories and the files under it. It will be realized that each directory D has a list of all directories that are its direct subdirectory. and each directory has a list of its direct and indirect subDirectoriesId-so. If I want to delete a directory, I will go through the list of its subDids and check if there is a file that I will continue to the tree until I reach the directory that I want to delete. The problem is this: Using this implementation, I will have to update id lists recursively, and this is a pain in the head. that after each addition or removal I will have to go back and update the lists. Another problem is that the runtime can be inefficient, because if I have a very wide and long tree, and I need to delete or add a directory that is located at the leaves of all the directories of the tree, I will have to go all over the tree, to do this.
Could you help me find a better implementation of DirectoryFile. I have the freedom to implement it the way I want, I really have a very short time for this. The proposed tree structure is just an idea, and I got a little stuck on it.
source share