Skip to content

Commit 0ede000

Browse files
[updated] readme
updated readme at ./Dynamic Programming/0 1 Knapsack/
1 parent a0b55ed commit 0ede000

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Dynamic Programming/0 1 Knapsack/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Output :
2525
A basic brute-force solution could be to try all combinations of the given items, allowing us to choose the one with maximum profit and a weight that doesn’t exceed ‘W.’ Take the example of 3 items, as shown in the diagram below. To try all the combinations, our algorithm will look like:
2626

2727
<div align="center">
28-
<img src="https://user-images.githubusercontent.com/72177954/135701909-41ccb37f-6280-4fec-b144-de4a48989b24.jpg">
28+
<img src="./Images/tree_dig.jpg">
2929
</div></br>
3030

3131
We can optimize this algorithm further with a 2D matrix. We can overcome the problem of calculating redundant cases and thus increased complexity. We can solve this problem by simply creating a 2-D array that can store a particular state (n, w) if we get it the first time. Now if we come across the same state (n, w) again instead of calculating it in exponential complexity we can directly return its result stored in the table in constant time. This method gives an edge over the recursive approach in this aspect.
@@ -138,11 +138,11 @@ We have reached our solution for max profit (with max weight capacity = 6) at DP
138138
## 💻 Input and Output
139139
- **Test Case 1 :**
140140

141-
![io 1](https://user-images.githubusercontent.com/72177954/135707806-ee72b296-541a-462a-ab9f-d3e4fabc31b8.png)
141+
![io 1](./Images/io_1.png)
142142

143143
- **Test Case 2 :**
144144

145-
![io 2](https://user-images.githubusercontent.com/72177954/135707940-3e153cc4-d1cd-4bc2-b518-f8a1bb294ed3.png)
145+
![io 2](./Images/io_2.png)
146146

147147
## ⏰ Time and Space complexity
148148
- **Time Complexity:** `O(N*W)`.

0 commit comments

Comments
 (0)