summaryrefslogtreecommitdiff
path: root/0x01
diff options
context:
space:
mode:
Diffstat (limited to '0x01')
-rw-r--r--0x01/README.md51
1 files changed, 50 insertions, 1 deletions
diff --git a/0x01/README.md b/0x01/README.md
index 38bed54..ec5a526 100644
--- a/0x01/README.md
+++ b/0x01/README.md
@@ -310,7 +310,27 @@ properties.
1. Exercise 4.1-2 from the textbook (10 marks)
- What does `FIND-MAXIMUM-SUBARRAY` return when all elements of `A` are negative?
+ Write pseudocode for the brute-force method of solving the maximum-subarray
+ problem. Your procedure should run in `theta(n^2)` time.
+
+ The following brute force solution uses a nested loop that yields a worst case
+ of `n^2` iterations.
+
+ ```
+ FIND-MAXIMUM-SUBARRAY(A,low,high)
+ l = low
+ r = high
+ total = -1
+ for i = low to high
+ sum = 0
+ for j = i to high
+ sum = sum + A[j]
+ if sum > total
+ total = sum
+ l = i
+ r = j
+ return l, r, total
+ ```
1. Exercise 4.2-1 from the textbook (5 marks)
@@ -323,6 +343,35 @@ properties.
Show your work.
+ ```plaintext
+ Strassens algorithm:
+
+ n
+ cij = sigma ai*k * bkj
+ k=1
+
+ c11 = a11 * b11 + a12 * b21
+ c12 = a11 * b12 + a12 * b22
+ c21 = a21 * b11 + a22 * b21
+ c22 = a21 * b12 + a22 * b22
+
+ A = |a11 a12| B = |b11 b12|
+ |a21 a22| |b21 b22|
+ A = |1 3| B = |6 8|
+ |7 5| |4 2|
+
+ c11 = (1 * 6) + (3 * 4) = 18
+ c12 = (1 * 8) + (3 * 2) = 14
+ c21 = (7 * 6) + (5 * 4) = 62
+ c22 = (7 * 8) + (5 * 2) = 66
+
+ |c11 c12|
+ |c21 c22|
+
+ |18 14|
+ |62 66|
+ ```
+
1. Exercise 4.3-2 from the textbook (10 marks)
Show that the solution of `T(n) = T([n/2]) + 1` is `O(lg n)`