wu :: forums
« wu :: forums - list the Combination of a string. »

Welcome, Guest. Please Login or Register.
May 18th, 2024, 2:41pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: towr, ThudnBlunder, Grimbal, william wu, SMQ, Icarus, Eigenray)
   list the Combination of a string.
« Previous topic | Next topic »
Pages: 1 2  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: list the Combination of a string.  (Read 3416 times)
SMQ
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 2084
Re: list the Combination of a string.  
« Reply #25 on: Sep 15th, 2009, 5:58am »
Quote Quote Modify Modify

on Sep 14th, 2009, 2:23pm, mistaken_id wrote:
Is there a way to extend this algorithm to print only combinations of strings.
 
For example; given an input "abc"
 
It should print
 
a
b
c
ab
ac
bc
abc
 
Lexicographic order of combinations.........

You could simply cull all out-of-order outputs from the algorithm.  I.e. change the first line of the loop to "if the first n characters are in increasing order output the first n characters."  That would roughly double the runtime but not change the complexity.
 
More efficient would probably be to just loop through each length and list the combinations directly, as here.
 
--SMQ
« Last Edit: Sep 15th, 2009, 5:59am by SMQ » IP Logged

--SMQ

Pages: 1 2  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board