Блог пользователя KunalSin9h

Автор KunalSin9h, история, 15 месяцев назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • -25
  • Проголосовать: не нравится

Автор KunalSin9h, история, 4 года назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится