0/1 knapsack problem recursive

The 0/1 Knapsack problem, as discussed, seeks to maximize the total value of items that can be included in a knapsack without exceeding its weight capacity. Each item has a specified weight and value, and the objective is to determine the optimal subset of items to include. Unlike the dynamic programming approach, solving the 0/1 … Read more

0/1 Knapsack using DP

The 0/1 Knapsack problem is a fundamental problem in combinatorial optimization. Given a set of items, each with a weight and a value, and a knapsack with a maximum weight capacity, the objective is to maximize the total value of items that can be included in the knapsack without exceeding its weight capacity. Each item … Read more

Sum of Subset using DP

The “Sum of Subset” problem is a classic example of a combinatorial problem that can be solved using recursion. The objective is to determine whether a subset of the given set of numbers can be found that sums up to a specific target value. This problem is significant in computer science, particularly in the fields … Read more

Sum of Subset using Recursion

The “Sum of Subset” problem is a classic example of a combinatorial problem that can be solved using recursion. The objective is to determine whether a subset of the given set of numbers can be found that sums up to a specific target value. This problem is significant in computer science, particularly in the fields … Read more

find the difference between two strings

To find the difference between two strings where one string is a permutation of another string with one additional character, you can use bit manipulation in Kotlin. This approach leverages the XOR operator to cancel out pairs of identical characters, leaving only the additional character as the result. Here’s how you can implement a function … Read more

Finding the missing number in an array

Finding the missing number in an array containing n distinct numbers taken from 0, 1, 2, …, n is a classic problem that can be efficiently solved using bit manipulation. The idea is to use the XOR operation, which has two useful properties for this problem: Given these properties, you can XOR all the numbers … Read more

Reversing the bits of an integer

Reversing the bits of an integer means to flip the order of the bits in its binary representation. For example, if you have a 32-bit integer, reversing the bits would mean the bit at position 0 (rightmost bit) moves to position 31 (leftmost bit), the bit at position 1 moves to position 30, and so … Read more

Detecting Power of Two

Detecting whether a given number is a power of two using bit manipulation is an efficient technique that leverages the properties of binary representation. A number is a power of two if it has exactly one bit set in its binary representation. For example, 2 (binary 10), 4 (binary 100), and 8 (binary 1000) are … Read more