Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-advanced-reader.ss" "lang")((modname |29.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu ;binary-contains? : (vectorof number) [sorted] N -> N or false
5 12687dd9 2023-08-04 jrmu Given avector (sorted) and key, determines the index of the key in the vector if it occurs using the binary-search algorithm. Otherwise, returns false.
6 12687dd9 2023-08-04 jrmu
7 12687dd9 2023-08-04 jrmu (define (binary-contains? avector key)
8 12687dd9 2023-08-04 jrmu (cond
9 12687dd9 2023-08-04 jrmu []
10 12687dd9 2023-08-04 jrmu []))
11 12687dd9 2023-08-04 jrmu
12 12687dd9 2023-08-04 jrmu #|
13 12687dd9 2023-08-04 jrmu
14 12687dd9 2023-08-04 jrmu Exercise 29.3.9. Develop the function binary-contains?. It consumes a sorted vector of numbers and a key, which is also a number. The goal is to determine the index of the key, if it occurs in the vector, or false. Use the binary-search algorithm from section 27.3.
15 12687dd9 2023-08-04 jrmu
16 12687dd9 2023-08-04 jrmu Determine the abstract running time of binary-contains? and compare with that of contains?, the function that searches for a key in a vector in the linear fashion of vector-contains-doll?.
17 12687dd9 2023-08-04 jrmu
18 12687dd9 2023-08-04 jrmu Suppose we are to represent a collection of numbers. The only interesting problem concerning the collection is to determine whether it contains some given number. Which data representation is preferable for the collection: lists or vectors? Why?
19 12687dd9 2023-08-04 jrmu
20 12687dd9 2023-08-04 jrmu |#