Subset Tree and permutation tree (subset and problem) of backtracking

Source: Internet
Author: User

One, subset tree
subset Tree : The corresponding solution space is called a subset tree When the given problem is to find a subset that satisfies a certain property from the set S of n elements. For example, the solution space tree for the 0-1 knapsack problem of that item is a subset tree. Such subset problems usually have 2^n leaf nodes, the total number of nodes is 2^ (n+1)-1. Any algorithm that traverses a subset tree requires an O (2^n) calculation time.

\

void Backtrack (int  t) {     if (t>N) output (x);     Else         for (int i=0; i<=1; i++) {            x[t]=i;             if (Legal (T)) backtrack (t+1);}        }

Second, arrange the tree
Arrange trees : When the given question is to determine the arrangement of n elements satisfying a certain nature, the corresponding solution space tree is called an arrangement tree . An arrangement tree usually has a n! leaf node. So traversing the arrangement tree requires O (n!) The calculation time.

void Backtrack (int  t) {     if (t>N) output (x);     Else         for (int i=t;i<=n;i++) {            swap (x[t], x[i]);             if (Legal (T)) backtrack (t+1);            Swap (X[t], x[i]);        

MORE: http://blog.csdn.net/liufeng_king/article/details/8762073

Subsets and issues:

Title Description: An example of a subset and a problem is 〈s,t〉. wherein, s={1 x, 2 x, ..., n x} is a set of positive integers, and C is a positive integer. Subsets and problems determine if there is a subset of S S1, so that the sum of each element in S1 equals C.

Http://blog.sina.com.cn/s/blog_7865b083010100dd.html

http://blog.csdn.net/sjf0115/article/details/6996804

http://blog.csdn.net/neilhappy/article/details/7313608

Subset Tree and permutation tree (subset and problem) of backtracking

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.