Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor code formatting in KnapsackMemoization.java and UnionFind.java
  • Loading branch information
CodaBlurd committed May 16, 2024
commit 58c7a781095174808610f7802b6947491eef6595
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ int solveKnapsackRecursive(int capacity, int[] weights, int[] profits, int numOf
return dpTable[numOfItems][capacity];
} else {
// case 1. include the item, if it is less than the capacity
int includeCurrentItem = profits[numOfItems - 1]
+ solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
int includeCurrentItem = profits[numOfItems - 1] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
Comment thread
vil02 marked this conversation as resolved.
Outdated


Comment thread
vil02 marked this conversation as resolved.
// case 2. exclude the item if it is more than the capacity
int excludeCurrentItem = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
Comment thread
vil02 marked this conversation as resolved.
Outdated
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/thealgorithms/searches/UnionFind.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public int find(int i) {
return i;
}

int result = find(parent);
p[i] = result;
int result = find(parent);
Comment thread
vil02 marked this conversation as resolved.
Outdated
p[i] = result;

return result;
}

Expand Down