• Now I understood your point #2 and #3. But still #1 is not clear for me...

    {(n)*(n+1)/2} cost of the naive implementation to {n +(n)*(n-1)/(2*k)}

    Again, if you could explain your formula's for my below example, i think it will be very useful for me as well as for others too.

    Declare @STR varchar(5)

    select @STR = ''

    select @STR = @STR + no from mystring

    step 1: '' + '1'

    step 2: '1' + '2'

    step 3: '12' + '3'

    step 4: '123' + '4'

    step 5: '1234' + '5'

    output of O(n) ?

    output of O(n^2). It is 15.

    output of {(n)*(n+1)/2}. Again 5*(5+1)/2 = 5*3 = 15

    output of {n +(n)*(n-1)/(2*k)}.

    If K= 1,

    =5+(5)*(5-1)/(2*1)

    =5+5*2

    =5+10

    =15

    {(n)*(n+1)/2} cost of the naive implementation to {n +(n)*(n-1)/(2*k)}

    how?

    {(n)*(n+1)/2} = 15

    {n +(n)*(n-1)/(2*k)} = 15

    There is no difference.

    If K= 0,

    =5+(5)*(5-1)/(2*0)

    "Divide By Zero error occured".

    How should i determine 'k' value? on what basis i have to determine the value?

    but I could get it down to O(n*Log(n)) time which is still a huge improvement

    Is it denotes FOR XML option?

    or

    Is it denotes Pseudo cursor method?

    Can you explain it?

    karthik