your question is very similar to this acm problem:
http://www.acmgnyr.org/year2009/e.pdf
and my approach was to find the number of characters at the end of string
that are sorted decreasingly e.g.  in "abcgda" the length of such sub-string
is 3 (  "gda" ) then look at the next char (here it is 'c' ) this character
must be replaced with the smallest character in the decreasing sub-sequence
which is bigger than this char (here it's 'd') then sort the decreasing
sub-string to be increasing

so the next lexicographical string of "abcgda" is "abdacg" ('d' is replaced
with 'c' and then "gca" is sorted to be "acg")

note that if a string is sorted decreasingly like "dcba" it's next char does
not exist so it's next string doesn't exist

On Mon, Jun 21, 2010 at 6:55 PM, nisha goyal <nisha.goyal1...@gmail.com>wrote:

> i think if we just reverse the last two alphabets of the string then also
> it will the next lexicographic string having the same alphabets.
>
> any comments??
>
>
> On 6/21/10, sharad kumar <sharad20073...@gmail.com> wrote:
>>
>> is this approach works
>> 1. write the post order traversal of T1 and T2 and save it in strings P1
>> and P2.
>> 2. similarly write the In order traversal of T1 and T2, saving it in
>> strings I1 and I2.
>> 3. if T1 contains T2, then P1 contains P2 and I1 contains I2 as
>> substrings.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to