TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

feat: add binary insertion sort algorithm

Open syedjafer opened this issue 2 years ago • 12 comments

syedjafer avatar Oct 25 '22 08:10 syedjafer

Hi @raklaptudirm, the existing binary search will return -1 if we don't find the element. But my modified version find the position of the element that is to be inserted in the array. So I cant reuse it.

syedjafer avatar Oct 25 '22 10:10 syedjafer

Ah, makes sense.

raklaptudirm avatar Oct 25 '22 11:10 raklaptudirm

@appgurueu Can you please review this PR

syedjafer avatar Oct 26 '22 06:10 syedjafer

Hi @raklaptudirm, the existing binary search will return -1 if we don't find the element. But my modified version find the position of the element that is to be inserted in the array. So I cant reuse it.

You could consider updating the existing binary search.

appgurueu avatar Oct 26 '22 06:10 appgurueu

@appgurueu See the actuall Binary Search should return -1 if the key is not found. But in my function, I will be returning the insertion position of the key element.

syedjafer avatar Oct 26 '22 06:10 syedjafer

@appgurueu See the actuall Binary Search should return -1 if the key is not found.

No. Our current implementation behaves this way because it is lazily written. More advanced implementations return the insertion or occurrence index; it is then trivial to check whether the element was found (arr[idx] === element).

appgurueu avatar Oct 26 '22 08:10 appgurueu

@appgurueu yeah, correct.

How to proceed mate ? Do i need to close this PR and create a new one for Binary Search or Include the fix for binary search in this PR itself. ?

syedjafer avatar Oct 26 '22 10:10 syedjafer

@appgurueu yeah, correct.

How to proceed mate ? Do i need to close this PR and create a new one for Binary Search or Include the fix for binary search in this PR itself. ?

I'd be fine with including the extension/feature (not a fix, the current implementation is correct) in this PR.

appgurueu avatar Oct 26 '22 11:10 appgurueu

@appgurueu I have created a PR for Binary Search Improvement https://github.com/TheAlgorithms/TypeScript/pull/72

syedjafer avatar Oct 26 '22 11:10 syedjafer

@appgurueu What about this PR? I think this can be closed

zFl4wless avatar Mar 17 '23 12:03 zFl4wless

@appgurueu What about this PR? I think this can be closed

It can be closed, yes, but why should it be closed? It would add something if it were merged. It's just that it currently depends on #72. The author should be able pick this up at any time.

appgurueu avatar Mar 17 '23 12:03 appgurueu

An sorry, I understood this wrongly. I thought this PR was canceled

zFl4wless avatar Mar 17 '23 12:03 zFl4wless