Deep Search and wide search

Source: Internet
Author: User

Let's talk about this mysterious deep search:

A few days ago my heart Daniel told me the deep search feeling is quite simple, but Daniel tell me deep search deep search so you don't know how to search

We also look at the same question: N's full array

For example, the full array of 3

123

213

321

This is the whole arrangement. We use a For loop to do this problem when we don't have a deep search, but if n is big, it's not going to work.

So we're going to have to go deep. In fact, in my opinion, deep search and recursion are brothers deep search is the enhanced version of recursion

I'll write a simple code for the DFS (deep search) function.

#include <stdio.h>intDfsintx) {    if(X >N) { for(i =0; I < n;i++) {printf ("%d", B[i]);//B[i] is the number that is recorded in the entire arrangement.            return; }    }     for(i =1; I <= n;i++)    {        if(A[i].biaozhi)//A[i].biaozhi is to see I used to contin if used.{A[i].biaozhi=1;//1 means to make the Biaozhi 0 when it's initialized.DFS (x +1);//each x represents the number of digits, and if this one is finished, then we'll fill in a place where we can output .A[i].biaozhi =0;//we're going to get the sign back for the next time .        }    }}

In fact, the meaning of deep search is always looking until you find a qualifying result and then return to the previous DFS to continue looking for

Guangzhou Search:

Daniel told me wide search is a lot easier than deep search, but I feel that I do not really, I would like to tell you the meaning of the broad search is a queue is advanced to the first search after the search

It will be easier to understand this wide search.

Deep Search and wide search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.