20-CS-4003-001 Organization of Programming Languages Fall 2017
Basic Operations

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

Binary Search

 
(define bs
   (lambda (x lst low high)
      (let ((mid (floor (/ (+ high low) 2))))
         (if (< high low)
             '()
             (if (= x (list-ref lst mid))
                 mid
                 (if (< x (list-ref lst mid))
                     (bs x lst low (- mid 1))
                     (bs x lst (+ mid 1) high)))))))

(define search
   (lambda (x lst)
      (bs x lst 0 (- (length lst) 1))))

(define ex '(2 6 7 10 21 22 23 33 34 39 51 53 54 55 60 70 73 74 80))