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 /notes.md | |
| parent | 82b87d4feda73bf1f5310df92670309538df43f2 (diff) | |
finish 2.1-4
Diffstat (limited to 'notes.md')
| -rw-r--r-- | notes.md | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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] +``` |
