This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: a 1 , a 2 , …, a n : distinct objects) i := 1 while ( i ≤ n and x ≠ a i ) i := i + 1 if i ≤ n then location := i else location := 0 { location is the subscript of the term that equals x , or is 0 if x is not found} ALGORITHM. The Binary Search Algorithm procedure binary search ( x : integer, a 1 , a 2 , …, a n : increasing integers) i := 1 { i is left endpoint of search interval} j := n { n is right endpoint of search interval} while i < j begin m := ⎣ ( i + j ) / 2 ⎦ if x > a m then i := m + 1 else j := m end if x = a i then location := i else location := 0 { location is the subscript of the term equal to x , or is 0 if x is not found} ALGORITHM. The Euclidean Algorithm procedure gcd( a, b : positive integers) x := a y := b while y ≠ 0 begin r := x mod y x := y y := r end {gcd( a , b ) is x }...
View
Full Document
 Spring '12
 sdaf
 Logic, Natural number, Euclidean algorithm

Click to edit the document details