Commit 24c677e

mo khan <mo@mokhan.ca>
2022-12-15 21:38:32
start work on chapter 3 exercise
1 parent 742e585
Changed files (2)
assignments/1.md
@@ -190,3 +190,21 @@
     list of numbers shown in Exercise 25, the output of your algorithm would be
     something like `Yes, the numbers 7 and 7 are adjacent to each other in the
     list`.
+
+## Chapter 3: Exercises
+
+21. Use the binary search algorithm to decide whether 35 is in the following
+    list: `3, 6, 7, 9, 12, 14, 18, 21, 22, 31, 43`
+
+    ```ruby
+    def search(target, items)
+      return false if items.empty?
+
+      mid = items.size / 2
+      return true if items[mid] == target
+      return items[mid] > target ? items[0..mid] : items[mid+1..-1]
+    end
+    ```
+
+    The comparisons are:
+
README.md
@@ -107,3 +107,5 @@ The formal term for "doable" is `effectively computable`.
 * top-down design: Viewing an operation at a high level of abstraction and
   fleshing out the details of its implementation at a later time constitute an
   imporant computer science problem-solving strategy.
+
+# Chapter 3: The Efficiency of Algorithms