Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

given these inputs x = 4, S = [1 2 3 4 5 6 7 8 9 10], and n = 10

 search (x,S,n) {
     i = 1
     j = n
     while i < j {
         m = [(i+j)/2]
         if x > Sm then i=n+1
         else j = m
     if x = Si then location = i
     else location = 0

This algorithm is from my discrete math hw. I'm confused as to what Sm would equal on the first iteration because m would be $\frac{11}{2}$. If i use a fraction as the index do I round down? Is there a general rule for this? Am I making any sense? Help pls

share|cite|improve this question
$[x]$ ($x$ in square brackets) means the integer part of $x$; for ex., $[3.2]=3$. – user35603 Apr 18 '14 at 19:19
up vote 1 down vote accepted

Yes, you should round down (or in other words, take only the integer part).


This is known as the floor function in mathematics (usually there is a floor(x) function in programming languages).

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.