|
-
February 3rd, 2009, 09:16 PM
#4
Re: using recursion to generate all possible bitstrings of length n
How about converting int to binary string then separate ? This is obviously not a smart solution since you work with low level binary digit which later on works with string. It consumes so much resources and longer time complexity 
 Originally Posted by dlorde
But for a more general solution, recursion can be useful.
You mind explaining in details of the usefullness you find in this problem, don't you ?
One simple recursive solution is to pass the array of items and a length value (starting at the array length) to a recursive method that iterates over the array up to the length value, and for each index it swaps the item at the index with the one at length - 1, then calls itself, passing the array and length - 1, then repeats the previous swap.
If this is tricky to grasp, it might help to step through the algorithm on paper.
That sounds descriptive but I am skeptical of its practicality. You care of posting some code for everyone to watch ?
The hardest part of the software task is arriving at a complete and consistent specification, and much of the essence of building a program is in fact the debugging of the specification...
F. Brooks
I see this kind of memos in all of your posts, could you stop borrow people's quotes and spread them like plague in all of the thread you join in? If you want to show people your views, then write yourself one after each post. he color and people's words are beautiful but your act of borrowing looks like a formal art of stealing in disguise. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|