diff options
| author | mo khan <mo@mokhan.ca> | 2021-09-06 19:18:38 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-09-06 19:18:38 -0600 |
| commit | a19f210d431fe51280d95448719feb96a8a319c2 (patch) | |
| tree | 0692db7cbfd4efbd1be3a1989d397e32959dd8d0 | |
| parent | e00bc7884d4139ff1400aa2573b55951a009ce5d (diff) | |
complete chapter 1
| -rw-r--r-- | 0x01/README.md | 79 | ||||
| -rw-r--r-- | README.md | 2 |
2 files changed, 80 insertions, 1 deletions
diff --git a/0x01/README.md b/0x01/README.md index 1c29d5b..201cb88 100644 --- a/0x01/README.md +++ b/0x01/README.md @@ -11,11 +11,90 @@ Submit your solutions to the following exercises and problems: 1. Exercise 1.1-4 * How are the shortest path and traveling-salesman problems given above similar? * How are they different? + + The shortest path problem is looking for an efficient solution that routes + from point A to point B. The traveling-salesman problem is similar except + that the sales person needs to visit multiple locations then return to the + starting point in the most efficient way. These problems are similar because + the shortest path from point A to B can be used to help determine a good + enough solution for the traveling-salesman problem. + + Both of these problems are considered an NP-complete problems because it + hasn't been proven if an efficient algorithm can or cannot exist. + + 1. Exercise 1.2-2 from the textbook (5 marks) * Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of size n, insertion sort runs in 8n^2 steps, while merge sort runs in 64nlg(n) steps. For which values of n does insertion sort beat merge sort? + + The following program produces a result of '44'. + + ```golang + func main() { + fmt.Println("n,isort,msort") + + for n := 2.0; n < 1000.0; n++ { + isort := 8 * math.Pow(n, 2) + msort := 64 * (n * math.Log2(n)) + + fmt.Printf("%v,%v,%v\n", n, isort, msort) + if isort > msort { + break + } + } + } + ``` + + ``csv + n,isort,msort + 2,32,128 + 3,72,304.312800138462 + 4,128,512 + 5,200,743.0169903639559 + 6,288,992.6256002769239 + 7,392,1257.6950050818066 + 8,512,1536 + 9,648,1825.876800830772 + 10,800,2126.033980727912 + 11,968,2435.439859520657 + 12,1152,2753.251200553848 + 13,1352,3078.7658454933885 + 14,1568,3411.390010163613 + 15,1800,3750.614971784178 + 16,2048,4096 + 17,2312,4447.159571280369 + 18,2592,4803.753601661543 + 19,2888,5165.4798563474 + 20,3200,5532.067961455824 + 21,3528,5903.274616214654 + 22,3872,6278.879719041314 + 23,4232,6658.683199315923 + 24,4608,7042.502401107696 + 25,5000,7430.169903639559 + 26,5408,7821.531690986777 + 27,5832,8216.445603738473 + 28,6272,8614.780020327225 + 29,6728,9016.412726956773 + 30,7200,9421.229943568356 + 31,7688,9829.12547980756 + 32,8192,10240 + 33,8712,10653.760380085054 + 34,9248,11070.319142560738 + 35,9800,11489.593957956724 + 36,10368,11911.507203323086 + 37,10952,12335.985569809354 + 38,11552,12762.9597126948 + 39,12168,13192.363938280172 + 40,12800,13624.135922911648 + 41,13448,14058.216460117852 + 42,14112,14494.549232429308 + 43,14792,14933.080604940173 + 44,15488,15373.759438082629 + ``` + + 1. Exercise 2.1-3 from the textbook. (10 marks) Consider the searching problem: @@ -47,7 +47,7 @@ When you have completed this objective, you should be able to #### Required Activities * [X] Watch the video, [Algorithmic Thinking, Peak Finding](https://www.youtube.com/watch?app=desktop&v=HtSuA80QTyo&list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb), on YouTube. -* [ ] Study Chapter 1 of the textbook. +* [X] Study Chapter 1 of the textbook. * [ ] Do Exercises 1.1-4 and 1.2-2 from the textbook as part of Assignment 1. #### Discussion Question |
