diff options
| author | mo khan <mo@mokhan.ca> | 2021-09-11 16:51:48 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-09-11 16:51:48 -0600 |
| commit | d3bd1fba66808b6a624dd746f54138e582148125 (patch) | |
| tree | d7e5353e02d09d2c72554926298d8dada4adfa8b | |
| parent | 82b87d4feda73bf1f5310df92670309538df43f2 (diff) | |
finish 2.1-4
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | notes.md | 15 |
2 files changed, 16 insertions, 1 deletions
@@ -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 @@ -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] +``` |
