A project that requires participants to provide algorithms for searching files in a given structure is taking place. As the lead engineer for your team, propose a model and its corresponding algorithm to efficiently traverse the presented folder structure. The algorithm should list each step in the process and the corresponding final order
The example of non-linear data structures are file directory structure. In which graph and various types of trees are used as the model and non-linear structures.
Here the traversal of the data can not be done in the linear order. Such kind of data structure are known as the non-linear data structures.
We use the two main algorithm in the traversal of the file and directory. Which is DFS (Depth first search) and BFS (Breadth first search). DFS works recursively while BFS search iteratively.
The algorithm for the traversal into the folder are given below -
BFS(Breadth first search)
create empty queue file and enqueue root directory.
Loop till queue becomes empty
pop front file fromt he queue
If poped file is directory,
Then, get the list of directory present in it, add each directory to the queue
and print every file.
Comments
Leave a comment