Subset BackTracking Problem

0 views
Skip to first unread message

Kyle E. deFreitas

unread,
Nov 8, 2010, 11:58:59 PM11/8/10
to design-and-analy...@googlegroups.com

Just sharing a simple solution to what was described in class

regards

--
Kyle deFreitas
St Vincent and the Grenadines
Contact #: 1-784-454-4037
or
1-868-722-5346
main.c

Irwin Williams

unread,
Nov 9, 2010, 8:37:48 PM11/9/10
to design-and-analy...@googlegroups.com
hmm,
Kyle, I guess being new to the whole backtracking thing, i'm not sure where you actually would say, "this is the backtracking step" in your solution (though it works):

public static void printSubset(int[] arr, int val, int i)
        {
            while (arr[i] <= val)
            {
                int k;
                for (k = 0; k <= i; k++) print(arr[k].ToString());
                print("\n");
                if (arr[i] < val)
                {
                    arr[i + 1] = arr[i] + 1;
                    printSubset(arr, val, i + 1);
                }
                arr[i]++;
--
Irwin Williams
785-1268
________________________
*I am a software solutions developer.*
Do you see a man skilled in his work?
He will serve before kings; he will not
serve before obscure men.
Proverbs 22:29

Kyle E. deFreitas

unread,
Nov 9, 2010, 9:07:51 PM11/9/10
to design-and-analy...@googlegroups.com
I think your looking for an explicit step that says "go back"

but I not sure what anyone else thinks?
Reply all
Reply to author
Forward
0 new messages