Subsequences show no ouput

https://ide.codingblocks.com/s/189205
Why it isnt showed any output!

@Kinjal
hello kinjal,
out[j]=inp[i]; should be after subsequences(inp,out,i+1,j); otherwise it will get overwrite

something like image

it will get overwrite by NULL char but I didnt understand that why it was overwritten in every subsequences by NULL!
Like in β€œab” - there is no output

@Kinjal
dry run for input ab u will get ur mistake

it was intentional because I did dry run. What I have found out in output [" " a a ab] That was my output in pen and paper. Can you tell me where I did wrong, Bhaiya!

@Kinjal
image
after making first call (highlighted part) output[j]=’\0’ right?
and then in next call output[j] will remain same i,e output[j]=’\0’. same procedure will repeat for j+1,j+2,j+3 …so on therefore evrytime evry generated subsequence is empty string .

Bhaiya, i’m thinking like a tree. So, in the first call, it will go to the end of left sub tree and satisfied the base case and out[j]=’\0’ and return nothing. After that it will go to the right child of that branch node (2nd node from the end of left sub tree) where only β€˜a’ is there so base case meets and print β€˜a’ and return nothing and it goes on like this.

@Kinjal
in u rightchild node when u will do output[j]=β€˜a’ and call subsequences(inp,out,i+1,j) and if u hit base case then u will again assign out[j]=’\0’ thats why u will again get empty string and not β€˜a’ in output

but bhaiya, rightchild node come to the picture by calling subsequences(inp,out,i+1,j+1) so it means, after out[j]=a, the j pointer increment by 1 place. Now when it again calls subsequences(inp,out,i+1,j) like you said then it will assign out[j]=’\0’. So, it’s like, [a|\0].

@Kinjal
show me ur tree

Google Photos

https://drive.google.com/file/d/10n1dhyl2FtVOw-x1rFx9jZQ_HVV9Y2Vq/view?usp=drivesdk

@Kinjal
image
when ur control will come back from highlighted part, b will be overwritten with null (becuase we are making chnages in original string out) and then when it go back to a same it will be null then in next brach same thing will happen

1 Like

thank you so much, Bhaiya.

@Kinjal
pls dont forgt to mark ur doubt as resolved