Introduction
Binary search algorithm is getting easy to write and I wrote one more time on Dec. 11 10:00 PM mock interview. I wrote the algorithm using C# language and the code passes all test cases.
Code review
Here is C# code.
Line 50: return binarySearch(x, n start, end);
I forgot to write a recursive call as line 50 shows. After the whiteboard testing, I wrote the test case Root(7, 3) and then I found out the bug.
Follow up
Dec. 19, 2017 10:14 PMBinary search range should be discussed based on x value, if x > 1, then the search range is [0, x]. But if x < 1, then search range is [x, 1] instead.
The mock interview practice has a bug related to range to search.
No comments:
Post a Comment