Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
If you`d like to have links in your filesystem (and you probably would) such as "/etc/.." -> "/".
My solution is that you need to add new type of file, where right edge is leading to linked file/folder.
I don't quite get it. So the left subtree contains all the directories within the current directory, and the right subtree is the first file within the current directory?Could you please draw out the binary tree with example?
I`m not sure how actually I can draw it any other way.
I can only convert it to windows filesystem (and change formatting slightly for convenience
(some left & right links skipped of course, left subtree starts under '/' and right under '\' )
"C:\"
/ \
null "C:\WINDOWS"
/ \
"C:\temp" "C:\WINDOWS\System32"
/ / \
"C:\boot.ini" "C:\WINDOWS\System" "C:\WINDOWS\System32\notepad.exe"
Does it make more sense?
I think, File system can be implemented using binary trees (or btrees etc). For example, in linux root directory can take the place of a root of the tree, with other files and directories underneath it.
eg: /
bin... etc ....
For adding a new directory we need to identify its parent directory in the tree and insert into it.
If it should be binary tree, I believe it`s fine. You can decide that node to the left is a file/folder inside the same folder as this one (it`ll be null for /). And right is a link to first file/folder inside this one.
So actually you`ll have linked list for file inside this foder (if nothing inside it or not a folder then null) and pointer to the next file/folder for parent folder (if last file/folder inside parent folder, then null)
Let`s try with pseudographics
- Anton January 18, 2014