KunalSin9h's blog

By KunalSin9h, history, 9 days ago, In English

While implementing Binary Search, we may face few problems, they are:

• What is the value of lower bound?

• What is the value of upper bound?

• How do I calculate my mid value?

• What condition should I write in my while loop?

• When my predicate is true, should I assign my mid to lower or upper bound?

• Whats my final answer, value of lower or upper bound?

Inspired from @Benq solutions, I wrote down all you need to know about correctly implementing binary search and its sub-classes (First True and last True), which works every time.

Read full Paper: Here on Academia.edu

Full text and comments »

  • Vote: I like it
  • -25
  • Vote: I do not like it

By KunalSin9h, history, 3 years ago, In English

I am solving a problem in which at some point i need to find answer for this sequence, when $$$n$$$ is known.

$$$n\times(n + 1) \; + \; (n - 1)\times n \; + \; (n - 2)\times (n - 1) \; + \; (n - 3)\times (n-2) \ldots 1\times 2$$$

it has $$$n$$$ terms.

Ans = $$$\frac{n \times (n + 1) \times (n + 2)}{3}$$$

thanks sam_2912 for help.

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it