Skip to content

Commit 3dbf017

Browse files
committed
docs: fix grammatical errors and typos
1 parent 97c7d91 commit 3dbf017

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

dynamic_programming/0_1_knapsack.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ namespace dynamic_programming {
3939
namespace knapsack {
4040
/**
4141
* @brief Picking up all those items whose combined weight is below
42-
* given capacity and calculating value of those picked items.Trying all
42+
* the given capacity and calculating the value of those picked items. Trying all
4343
* possible combinations will yield the maximum knapsack value.
4444
* @tparam n size of the weight and value array
4545
* @param capacity capacity of the carrying bag
46-
* @param weight array representing weight of items
47-
* @param value array representing value of items
48-
* @return maximum value obtainable with given capacity.
46+
* @param weight array representing the weight of items
47+
* @param value array representing the value of items
48+
* @return maximum value obtainable with a given capacity.
4949
*/
5050
template <size_t n>
5151
int maxKnapsackValue(const int capacity, const std::array<int, n> &weight,
5252
const std::array<int, n> &value) {
5353
std::vector<std::vector<int> > maxValue(n + 1,
5454
std::vector<int>(capacity + 1, 0));
5555
// outer loop will select no of items allowed
56-
// inner loop will select capcity of knapsack bag
56+
// inner loop will select the capacity of the knapsack bag
5757
int items = sizeof(weight) / sizeof(weight[0]);
5858
for (size_t i = 0; i < items + 1; ++i) {
5959
for (size_t j = 0; j < capacity + 1; ++j) {
@@ -62,22 +62,22 @@ int maxKnapsackValue(const int capacity, const std::array<int, n> &weight,
6262
// will be zero
6363
maxValue[i][j] = 0;
6464
} else if (weight[i - 1] <= j) {
65-
// if the ith item's weight(in actual array it will be at i-1)
65+
// if the ith item's weight(in the actual array it will be at i-1)
6666
// is less than or equal to the allowed weight i.e. j then we
6767
// can pick that item for our knapsack. maxValue will be the
6868
// obtained either by picking the current item or by not picking
6969
// current item
7070

71-
// picking current item
71+
// picking the current item
7272
int profit1 = value[i - 1] + maxValue[i - 1][j - weight[i - 1]];
7373

74-
// not picking current item
74+
// not picking the current item
7575
int profit2 = maxValue[i - 1][j];
7676

7777
maxValue[i][j] = std::max(profit1, profit2);
7878
} else {
79-
// as weight of current item is greater than allowed weight, so
80-
// maxProfit will be profit obtained by excluding current item.
79+
// as the weight of the current item is greater than the allowed weight, so
80+
// maxProfit will be profit obtained by excluding the current item.
8181
maxValue[i][j] = maxValue[i - 1][j];
8282
}
8383
}
@@ -90,7 +90,7 @@ int maxKnapsackValue(const int capacity, const std::array<int, n> &weight,
9090
} // namespace dynamic_programming
9191

9292
/**
93-
* @brief Function to test above algorithm
93+
* @brief Function to test the above algorithm
9494
* @returns void
9595
*/
9696
static void test() {

dynamic_programming/armstrong_number.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ int main() {
1818
count++;
1919
}
2020

21-
/* Calaculation for checking of armstrongs number i.e.
22-
in a n digit number sum of the digits raised to a power of n
21+
/* Calculation for checking of armstrongs number i.e.
22+
in an n-digit number sum of the digits is raised to a power of n
2323
is equal to the original number */
2424

2525
temp = n;

0 commit comments

Comments
 (0)