Value of k is s

why value of k is always stared with s and not to 0. plz give a example to show that

hello @kingshuk441,
initialising k with s makes implementation easy.
we dont need to add or subtract anything.

if u want to stores values starting from 0 indices then that is also correct .

for k=0 it is giving garbage values after sorting

if u are storing from indices 0 then make sure u are accessing same indices while copy values to original array.

also pls share ur code.

image
this is the error.

here in temp array u are accessing values from indices s to e.
but u have stored values in temp array from indices 0 to k

it should be something as
image

why this i+s
can u plz explain with a example

see index 0 of temp array means index s of original array.
index 1 of temp array means index s+1 of original array.
index 2 of temp array means index s+2 of original array.
index i of temp array means index i+s of original array.
thats why while copying values back to original array.
i m using
ar[i+s]=temp[i]

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.