Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
asgs115636yThe lines 4 and 5 in that method adjust the appropriate indices and run recursively. "mid + 1" is the clue here
-
donuts238486y@asgs so that would mean the end parameter is inclusive. Otherwise it would be skipping mid?
Now I see the for (int i=0; i< (mid-low+1);i++)
What's looking for a <= so basically this would mean the Left side will always have the 1 more item than the right if and odd succeed array is the input?
Guess is the "indexes start at 0" thing that makes it tricky... -
donuts238486y@asgs but how do you instinctively think like this. I guess this is why I hate sorting, tree arrays so much.
I can never figure out the indexing calculation quickly -
asgs115636y@billgates it just takes more and more practice.
More importantly, you need to rubberduck. Explain it with examples - simple ones - arrays of smaller sizes, odd and even both. It is called base case or something. Then you generalize it and write code like a Boss -
donuts238486y@asgs rubber duck it's what I do but I can't seem to like I dunno... Google/FB devs? That can sorta go "isn't using I < mid-low+1) obvious"
Otherwise how the fck can they pass those tech interviews?
Related Rants
How come when implementing merge sort the mid doesn't need to deal with odd/even division?
I know int will always go down if there is decimal but how will it cover the whole array?
Full code:
https://gist.github.com/allanx2000/...
I guess in general, array indexing that involves dynamic cutoffs always confuse me.
How do you think about them without having to try things out on paper?
question
algorithms
merge sort