Deep search algorithm
What is the depth search algorithm?
Deep search algorithms (Depth First Search - DFS for short), also called depth-first search algorithms, are algorithms that browse or search on a tree or graph and use the stack ( stack) to remember adjacent vertices to start the search when the adjacent vertex is not encountered in any loop. The algorithm continues until you reach the top of the search or a node without children. Then the algorithm returns to the top that has just been searched in the previous step.
In the above illustration, the first depth search algorithm browses from vertices A to B to C to D then to E , then to F and finally to G. This algorithm follows the following rule:
Rule 1 : Browse to the adjacent vertices without approval. Mark the vertex that has been approved. Display that vertex and push into a stack.
Rule 2 : If no adjacent vertices are found, then take a vertex from the stack (pop up operation). (The algorithm will retrieve all vertices from the stack without any adjacent vertices)
Rule 3 : Repeat rules 1 and rule 2 until the stack is empty.
The following table illustrates the rules with the example image above:
Initialize stack (stack)
Mark the top S as approved and place this vertex in the stack. Search for any adjacent vertices that have not been approved from the top S. We have 3 vertices and we can take any of them. For example, we take vertex A in alphabetical order.
Mark the top A as approved and place it in the stack. Search for any adjacent vertices with vertex A. Both S and D are adjacent two vertices A but we only care about the unopened vertex.
Browse vertex D , mark this vertex as browsed and place it in the stack. Here, we have B and C as two vertices adjacent to D and both are unapproved. We will choose alphabetically again.
Select B , mark as browsed and place in the stack. Here B does not have any adjacent vertices that have not been approved. So we take B out of the stack.
Check the top element of the stack to return to the previously browsed node and check if this vertex is adjacent but not yet approved. Here, we find vertex D at the top of the stack.
Only one vertex adjacent to D has not been approved, it is vertex C. We browsed C , marked as browsed and placed in the stack.
Since C does not have any adjacent vertices that have not been approved, we continue to take the vertices from the stack to find out if there are any adjacent vertices that have not been approved. In this example is not available, and we continue until the stack is empty.
According to Tutorialspoint
Previous article: Graph data structure (Graph)
Next lesson: Search algorithm by width
You should read it
May be interested
- 12 best search engines discover Deep web and Dark webto explore the hidden web, you need to use other search engines. here are 12 services to perform sunken web search.
- How to Use ChatGPT Search Like a Prowhether you're troubleshooting a technical issue or digging deep into research, chatgpt search can be surprisingly effective.
- Is Google's Helpful Content Algorithm Really Helpful?in a context where ai tools like chatgpt, bard or bing ai are increasingly reducing search volume on search engines like google
- What is algorithm?algorithms (also known as algorithms - english is algorithms) is a finite set of instructions to be executed in a certain order to get the desired result. in general, the algorithm is independent of programming languages, ie an algorithm can be deployed in many different programming languages.
- Shell Sort in data structure and algorithmshell sort is a highly efficient sorting algorithm based on insertion sorting algorithm (insertion sort). this algorithm avoids the case of swapping positions of two distant elements in the selection algorithm (if the smaller element is in the right position quite far from the larger element on the left).
- How does YouTube algorithm work?have you ever wondered how youtube algorithm works?
- Google changed the search ranking algorithm, limiting the display of fake newssee how google changes the search ranking algorithm, limiting the display of fake news!
- Google 'prioritizes' sites that use HTTPS protocolgoogle is quietly changing some of the algorithms included in the ranking list of sites returned from google search. accordingly, google will favor web sites that use https security protocols.
- A guide to the Deep Web for newbiesperhaps you have heard about the hidden internet called deep web or darknet that is not accessible from google and it is hidden for most ordinary web surfers. so how to enter the deep web, read this article!
- Selection sort algorithm (Selection Sort)selection sort is a simple algorithm. this sorting algorithm is an algorithm based on in-place comparison, in which the list is divided into two parts, sorted (list) on the left and unsorted (unsorted list) in the right. initially, the sorted part is blank and the unordered part is the original list.