You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/chapters/greedy-algorithms--knapsack-problem.adoc
+16-8Lines changed: 16 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,19 +24,27 @@ So, we have 4 items that we can take. We can't take them all because the total w
24
24
How would you solve this problem?
25
25
26
26
27
-
28
27
First, we have to make a *greedy choice*. This is the heuristic function that we are going to use to determine which choice to make on each step. Let's explore our options:
29
28
30
-
We can take items with the *largest* value in hopes to get maximize profit. Based on that we can make take the last item and first having a total weight of 7 and total value of 8.
29
+
- We can take items with the *largest* value in hopes to get maximize profit. Based on that we can make take the last item and first having a total weight of 7 and total value of 8.
31
30
32
-
Also, we could take items *smallest* weight so we can fit as much as possible. Let's analyze both options. So we can take the first 2 items for a total value of 5 and total weight of 4. This is not good.
31
+
- Also, we could take items *smallest* weight so we can fit as much as possible. Let's analyze both options. So we can take the first 2 items for a total value of 5 and total weight of 4. This is worst! [big]#👎#
33
32
34
-
Finally, we can take items based on the *best* value/weight ratio.
33
+
- One last idea, we can take items based on the *best* value/weight ratio and take fractions of an item to fill up the knapsack to maximum weight. In that case, we can take the last item and 2/3 of the 2nd item. We get a total value of `9.67` and total weight of `7`.
Copy file name to clipboardExpand all lines: book/chapters/sample.adoc
+27-5Lines changed: 27 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,38 @@
1
+
= Sample Section
2
+
3
+
4
+
:leveloffset: +1
5
+
6
+
// ------------------
7
+
8
+
1
9
= Sample Title 1
2
10
3
-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Provident architecto soluta commodi odit accusamus non molestias necessitatibus, culpa possimus repudiandae, ex sit officiis, sint hic doloribus harum vero quisquam aspernatur.
11
+
Provident architecto soluta commodi odit accusamus non molestias necessitatibus, culpa possimus repudiandae, ex sit officiis, sint hic doloribus harum vero quisquam aspernatur.
4
12
5
13
== Sample Title 2
6
14
7
-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio ab voluptate impedit, iusto explicabo tempore? Ipsam eaque accusamus mollitia accusantium quod aperiam. Sit cum tempora quod! Placeat assumenda adipisci eius?
15
+
Optio ab voluptate impedit, iusto explicabo tempore? Ipsam eaque accusamus mollitia accusantium quod aperiam. Sit cum tempora quod! Placeat assumenda adipisci eius?
8
16
9
17
=== Sample Title 3
10
18
11
-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, vero facere voluptatem impedit optio fuga accusamus non dignissimos, exercitationem culpa error debitis, molestiae corporis? Repudiandae eum dolor quae nemo reiciendis.
19
+
Quisquam, vero facere voluptatem impedit optio fuga accusamus non dignissimos, exercitationem culpa error debitis, molestiae corporis? Repudiandae eum dolor quae nemo reiciendis.
12
20
13
21
==== Sample Title 4
14
22
15
-
Lorem ipsum dolor sit amet consectetur adipisicing elit. Error incidunt provident cumque eum totam perspiciatis ab corrupti officia pariatur, cum nulla. Commodi quisquam ratione repudiandae natus sapiente ipsum quidem suscipit!
23
+
Laboris commodo labore anim ea. Nostrud culpa Lorem enim labore esse qui enim incididunt sunt eiusmod cupidatat veniam enim irure. Culpa velit duis duis esse amet adipisicing fugiat dolore do minim exercitation. Nostrud magna id nostrud nostrud minim cupidatat. Sunt amet qui amet deserunt commodo Lorem.
16
24
17
25
===== Sample title 5
18
26
19
-
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Cum, quisquam illum laudantium sed eius saepe itaque ad incidunt neque ex, tempora earum possimus quis provident minus alias corporis numquam ullam?
27
+
Irure nisi laboris amet do sit Lorem do. Aliqua esse ex in dolore nulla. Aute deserunt nostrud eiusmod fugiat aliquip proident ad eiusmod incididunt est in nisi deserunt Lorem.
28
+
29
+
====== Sample title 6
30
+
31
+
Et nisi fugiat in culpa id voluptate incididunt anim commodo. Irure non dolor velit irure non incididunt nisi laborum minim. Elit duis consectetur aliqua laborum tempor et nulla. Nulla dolore magna dolor occaecat velit magna sint nulla. Proident veniam officia in nisi cillum ut deserunt consequat mollit laborum.
32
+
33
+
======= Sample title 7
34
+
35
+
Ullamco ipsum consequat consequat in pariatur ad tempor nisi minim deserunt sunt ex. Minim enim irure quis aliqua anim nisi amet aliquip labore excepteur nisi amet commodo mollit. Est dolor eu commodo Lorem cillum. Elit deserunt cillum excepteur proident aliquip sunt incididunt. Deserunt voluptate enim incididunt incididunt pariatur.
20
36
21
37
22
38
== Code
@@ -53,6 +69,7 @@ BigInt allows to operate beyond the maximum safe limit of integers (Number.MAX_S
Copy file name to clipboardExpand all lines: notes.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@
6
6
-[ ] Refactor LinkedList.remove(). It's doing to much maybe it can be refactor in terms of removeByPosition and indexOf
7
7
-[ ] More algorithm and datastructres! Greedy, Divide and Conquer etc.
8
8
-[ ] Algorithms visualizations like https://bost.ocks.org/mike/algorithms/
9
+
-[ ] sorting algorithms needs a comparator. So, it can sort objects as well. Replace `Array.sort` for `mergesort` in `src/algorithms/knapsack-fractional.js`
0 commit comments