summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2021-09-11 16:51:48 -0600
committermo khan <mo@mokhan.ca>2021-09-11 16:51:48 -0600
commitd3bd1fba66808b6a624dd746f54138e582148125 (patch)
treed7e5353e02d09d2c72554926298d8dada4adfa8b
parent82b87d4feda73bf1f5310df92670309538df43f2 (diff)
finish 2.1-4
-rw-r--r--README.md2
-rw-r--r--notes.md15
2 files changed, 16 insertions, 1 deletions
diff --git a/README.md b/README.md
index 7827912..175e692 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,7 @@ When you have completed this objective, you should be able to
* [ ] Study Section 4.1 of the textbook.
* [X] Study Section 2.1 of the textbook.
-* [ ] Do Exercise 2.1-3 from the textbook as part of Assignment 1.
+* [X] Do Exercise 2.1-3 from the textbook as part of Assignment 1.
#### Learning Objective 1.2.2 – Analyzing Algorithms
diff --git a/notes.md b/notes.md
index b2e9cfc..4f5273b 100644
--- a/notes.md
+++ b/notes.md
@@ -345,3 +345,18 @@ return i
* termination: terminate loop when the key matches the target value.
2.1-4:
+
+Consider the problem of adding two `n-bit` binary integers, stored in two
+`n-element` arrays `A` and `B`. The sum of the two integers should be stored in
+binary form in an `(n + 1)-element` array `C`. State the problem formally and
+write pseudocode for adding two integers.
+
+Input: Two sequences of `n` numbers `A = {a1,a2,...aN}` and `B = {b1,b2,...,bN}`
+Output: A sequence `C` with `n+1` numbers such that `C = {a1+b1,a2+b2,...,aN+bN}`
+
+```plaintext
+i = 0
+max = 2 ** A.length
+for i < A.length
+ C[i] = A[i] + B[i]
+```