Unbounded Knapsack (Repetition of items allowed)
Last Updated :
23 Jul, 2025
Given a knapsack weight, say capacity and a set of n items with certain value vali and weight wti, The task is to fill the knapsack in such a way that we can get the maximum profit. This is different from the classical Knapsack problem, here we are allowed to use an unlimited number of instances of an item.
Examples:
Input: capacity = 100, val[] = [1, 30], wt[] = [1, 50]
Output: 100
Explanation: There are many ways to fill knapsack.
1) 2 instances of 50 unit weight item.
2) 100 instances of 1 unit weight item.
3) 1 instance of 50 unit weight item and 50 instances of 1 unit weight items.
We get maximum value with option 2.
Input: capacity = 8, val[] = [10, 40, 50, 70], wt[] = [1, 3, 4, 5]
Output : 110
Explanation: We get maximum value with one unit of weight 5 and one unit of weight 3.
Using Recursive Method - O(2^n) time and O(capacity) space
The idea is to explore the two possibilities for each item in the list. We start by considering the first item and check if it can be included in the knapsack, meaning its weight is less than or equal to the current remaining weight capacity.
- If we include the item, we add its value to the total profit and recursively solve the problem with the same item but with reduced weight.
- If we exclude the item, we move to the next item in the list without changing the weight. The recursion continues until we have considered all items, and the maximum profit is obtained by either including or excluding each item in every step.
The solution is found by returning the maximum of the two choices-whether to include or exclude the item at each stage.The recurrence relation can be expressed as:
- knapSackRecur(i, capacity) = max(knapSackRecur(i, capacity - wt[i]) + val[i], knapSackRecur(i + 1, capacity))
C++
// C++ program to implement
// unbounded knapsack problem using recursion.
#include <bits/stdc++.h>
using namespace std;
int knapSackRecur(int i, int capacity, vector<int> &val, vector<int> &wt) {
if (i==val.size()) return 0;
// Consider current item only if
// its weight is less than equal
// to maximum weight.
int take = 0;
if (wt[i]<=capacity) {
take = val[i] + knapSackRecur(i, capacity-wt[i], val, wt);
}
// Skip the current item
int noTake = knapSackRecur(i+1, capacity, val, wt);
// Return maximum of the two.
return max(take, noTake);
}
int knapSack(int capacity, vector<int> &val, vector<int> &wt) {
return knapSackRecur(0, capacity, val ,wt);
}
int main() {
vector<int> val = {1, 1}, wt = {2, 1};
int capacity = 3;
cout << knapSack(capacity, val, wt);
}
Java
// Java program to implement
// unbounded knapsack problem using recursion.
class GfG {
static int knapSackRecur(int i, int capacity, int[] val, int[] wt) {
if (i == val.length) return 0;
// Consider current item only if
// its weight is less than equal
// to maximum weight.
int take = 0;
if (wt[i] <= capacity) {
take = val[i] + knapSackRecur(i, capacity - wt[i], val, wt);
}
// Skip the current item
int noTake = knapSackRecur(i + 1, capacity, val, wt);
// Return maximum of the two.
return Math.max(take, noTake);
}
static int knapSack(int capacity, int[] val, int[] wt) {
return knapSackRecur(0, capacity, val, wt);
}
public static void main(String[] args) {
int[] val = {1, 1};
int[] wt = {2, 1};
int capacity = 3;
System.out.println(knapSack(capacity, val, wt));
}
}
Python
# Python program to implement
# unbounded knapsack problem using recursion.
def knapSackRecur(i, capacity, val, wt):
if i == len(val):
return 0
# Consider current item only if
# its weight is less than equal
# to maximum weight.
take = 0
if wt[i] <= capacity:
take = val[i] + knapSackRecur(i, capacity - wt[i], val, wt)
# Skip the current item
noTake = knapSackRecur(i + 1, capacity, val, wt)
# Return maximum of the two.
return max(take, noTake)
def knapSack(capacity, val, wt):
return knapSackRecur(0, capacity, val, wt)
if __name__ == "__main__":
val = [1, 1]
wt = [2, 1]
capacity = 3
print(knapSack(capacity, val, wt))
C#
// C# program to implement
// unbounded knapsack problem using recursion.
using System;
class GfG {
static int knapSackRecur(int i, int capacity, int[] val, int[] wt) {
if (i == val.Length) return 0;
// Consider current item only if
// its weight is less than equal
// to maximum weight.
int take = 0;
if (wt[i] <= capacity) {
take = val[i] + knapSackRecur(i, capacity - wt[i], val, wt);
}
// Skip the current item
int noTake = knapSackRecur(i + 1, capacity, val, wt);
// Return maximum of the two.
return Math.Max(take, noTake);
}
static int knapSack(int capacity, int[] val, int[] wt) {
return knapSackRecur(0, capacity, val, wt);
}
static void Main() {
int[] val = {1, 1};
int[] wt = {2, 1};
int capacity = 3;
Console.WriteLine(knapSack(capacity, val, wt));
}
}
JavaScript
// JavaScript program to implement
// unbounded knapsack problem using recursion.
function knapSackRecur(i, capacity, val, wt) {
if (i === val.length) return 0;
// Consider current item only if
// its weight is less than equal
// to maximum weight.
let take = 0;
if (wt[i] <= capacity) {
take = val[i] + knapSackRecur(i, capacity - wt[i], val, wt);
}
// Skip the current item
let noTake = knapSackRecur(i + 1, capacity, val, wt);
// Return maximum of the two.
return Math.max(take, noTake);
}
function knapSack(capacity, val, wt) {
return knapSackRecur(0, capacity, val, wt);
}
const val = [1, 1];
const wt = [2, 1];
const capacity = 3;
console.log(knapSack(capacity, val, wt));
Using Top-Down DP (Memoization) – O(n*capacity) Time and O(n*capacity) Space
If we notice carefully, we can observe that the above recursive solution holds the following two properties of Dynamic Programming.
1. Optimal Substructure: The Unbounded Knapsack Problem has an optimal substructure property, meaning the solution to the problem can be derived from the solutions to smaller subproblems. Specifically, for any given item i and remaining capacity w, we can express the recursive relation as follows:
- Include the current item: If the weight of the current item wt[i] is less than or equal to the current capacity w, we can include it multiple times. The new problem becomes knapSack(i, capacity - wt[i], val, wt), where i does not increment because repetition of items is allowed.
- Exclude the current item: If we do not include the current item, the problem becomes knapSack(i + 1, capacity, val, wt).
2. Overlapping Subproblems: When implementing the recursive solution, we notice that many subproblems are computed multiple times. For example, in the recursive call knapSack(i, capacity), we might need to compute knapSack(i, capacity - wt[i]) and knapSack(i + 1, capacity) multiple times, especially when the weight w is large.
- There are two parameters i and capacity that changes in the recursive solution. So we create a 2D matrix of size n*(capacity+1) for memoization.
- We initialize this matrix as -1 to indicate nothing is computed initially.
- Now we modify our recursive solution to first check if the value is -1, then only make recursive calls. This way, we avoid re-computations of the same subproblems.
C++
// C++ program to implement
// unbounded knapsack problem using memoization.
#include <bits/stdc++.h>
using namespace std;
int knapSackRecur(int i, int capacity, vector<int> &val,
vector<int> &wt, vector<vector<int>> &memo) {
if (i == val.size())
return 0;
// If value is memoized.
if (memo[i][capacity] != -1)
return memo[i][capacity];
// Consider current item only if
// its weight is less than equal
// to maximum weight.
int take = 0;
if (wt[i] <= capacity) {
take = val[i] + knapSackRecur(i, capacity - wt[i],
val, wt, memo);
}
// Skip the current item
int noTake = knapSackRecur(i + 1, capacity, val, wt, memo);
// store maximum of the two and return it.
return memo[i][capacity] = max(take, noTake);
}
int knapSack(int capacity, vector<int> &val, vector<int> &wt) {
// 2D matrix for memoization.
vector<vector<int>> memo(val.size(), vector<int>(capacity + 1, -1));
return knapSackRecur(0, capacity, val, wt, memo);
}
int main() {
vector<int> val = {1, 1}, wt = {2, 1};
int capacity = 3;
cout << knapSack(capacity, val, wt);
}
Java
// Java program to implement
// unbounded knapsack problem using memoization.
import java.util.Arrays;
class GfG {
static int knapSackRecur(int i, int capacity, int[] val,
int[] wt, int[][] memo) {
if (i == val.length)
return 0;
// If value is memoized.
if (memo[i][capacity] != -1)
return memo[i][capacity];
// Consider current item only if
// its weight is less than equal
// to maximum weight.
int take = 0;
if (wt[i] <= capacity) {
take = val[i]
+ knapSackRecur(i, capacity - wt[i], val, wt,
memo);
}
// Skip the current item
int noTake = knapSackRecur(i + 1, capacity, val, wt, memo);
// store maximum of the two and return it.
return memo[i][capacity] = Math.max(take, noTake);
}
static int knapSack(int capacity, int[] val, int[] wt) {
// 2D matrix for memoization.
int[][] memo = new int[val.length][capacity + 1];
for (int i = 0; i < val.length; i++) {
Arrays.fill(memo[i], -1);
}
return knapSackRecur(0, capacity, val, wt, memo);
}
public static void main(String[] args) {
int[] val = { 1, 1 };
int[] wt = { 2, 1 };
int capacity = 3;
System.out.println(knapSack(capacity, val, wt));
}
}
Python
# Python program to implement
# unbounded knapsack problem using memoization.
def knapSackRecur(i, capacity, val, wt, memo):
if i == len(val):
return 0
# If value is memoized.
if memo[i][capacity] != -1:
return memo[i][capacity]
# Consider current item only if
# its weight is less than equal
# to maximum weight.
take = 0
if wt[i] <= capacity:
take = val[i] + knapSackRecur(i, capacity - wt[i], val, wt, memo)
# Skip the current item
noTake = knapSackRecur(i + 1, capacity, val, wt, memo)
# store maximum of the two and return it.
memo[i][capacity] = max(take, noTake)
return memo[i][capacity]
def knapSack(capacity, val, wt):
# 2D matrix for memoization.
memo = [[-1 for _ in range(capacity + 1)] for _ in range(len(val))]
return knapSackRecur(0, capacity, val, wt, memo)
if __name__ == "__main__":
val = [1, 1]
wt = [2, 1]
capacity = 3
print(knapSack(capacity, val, wt))
C#
// C# program to implement
// unbounded knapsack problem using memoization.
using System;
class GfG {
static int knapSackRecur(int i, int capacity, int[] val,
int[] wt, int[, ] memo) {
if (i == val.Length)
return 0;
// If value is memoized.
if (memo[i, capacity] != -1)
return memo[i, capacity];
// Consider current item only if
// its weight is less than equal
// to maximum weight.
int take = 0;
if (wt[i] <= capacity) {
take = val[i]
+ knapSackRecur(i, capacity - wt[i], val, wt,
memo);
}
// Skip the current item
int noTake = knapSackRecur(i + 1, capacity, val, wt, memo);
// store maximum of the two and return it.
return memo[i, capacity] = Math.Max(take, noTake);
}
static int knapSack(int capacity, int[] val, int[] wt) {
// 2D matrix for memoization.
int[, ] memo = new int[val.Length, capacity + 1];
for (int i = 0; i < val.Length; i++) {
for (int j = 0; j <= capacity; j++) {
memo[i, j] = -1;
}
}
return knapSackRecur(0, capacity, val, wt, memo);
}
static void Main() {
int[] val = { 1, 1 };
int[] wt = { 2, 1 };
int capacity = 3;
Console.WriteLine(knapSack(capacity, val, wt));
}
}
JavaScript
// JavaScript program to implement
// unbounded knapsack problem using memoization.
function knapSackRecur(i, capacity, val, wt, memo) {
if (i === val.length) return 0;
// If value is memoized.
if (memo[i][capacity] !== -1) return memo[i][capacity];
// Consider current item only if
// its weight is less than equal
// to maximum weight.
let take = 0;
if (wt[i] <= capacity) {
take = val[i] + knapSackRecur(i, capacity - wt[i], val, wt, memo);
}
// Skip the current item
let noTake = knapSackRecur(i + 1, capacity, val, wt, memo);
// store maximum of the two and return it.
memo[i][capacity] = Math.max(take, noTake);
return memo[i][capacity];
}
function knapSack(capacity, val, wt) {
// 2D matrix for memoization.
let memo = Array.from({ length: val.length }, () => Array(capacity + 1).fill(-1));
return knapSackRecur(0, capacity, val, wt, memo);
}
const val = [1, 1];
const wt = [2, 1];
const capacity = 3;
console.log(knapSack(capacity, val, wt));
Using Bottom-Up DP (Tabulation) – O(n*capacity) Time and O(n*capacity) Space
The idea is to fill the dp table based on previous values. For each item, we either include it or exclude it to compute the maximum value for each given knapsack weight. The table is filled in an iterative manner from i = n-1 to i = 0 and for each weight from 1 to capacity.
C++
// C++ program to implement
// unbounded knapsack problem using tabulation
#include <bits/stdc++.h>
using namespace std;
int knapSack(int capacity, vector<int> &val, vector<int> &wt) {
// 2D matrix for tabulation.
vector<vector<int>> dp(val.size() + 1, vector<int>(capacity + 1, 0));
// Calculate maximum profit for each
// item index and knapsack weight.
for (int i = val.size() - 1; i >= 0; i--) {
for (int j = 1; j <= capacity; j++) {
int take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[i][j - wt[i]];
}
int noTake = dp[i + 1][j];
dp[i][j] = max(take, noTake);
}
}
return dp[0][capacity];
}
int main() {
vector<int> val = {1, 1}, wt = {2, 1};
int capacity = 3;
cout << knapSack(capacity, val, wt);
}
Java
// Java program to implement
// unbounded knapsack problem using tabulation
class GfG {
static int knapSack(int capacity, int[] val, int[] wt) {
// 2D matrix for tabulation.
int[][] dp = new int[val.length + 1][capacity + 1];
// Calculate maximum profit for each
// item index and knapsack weight.
for (int i = val.length - 1; i >= 0; i--) {
for (int j = 1; j <= capacity; j++) {
int take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[i][j - wt[i]];
}
int noTake = dp[i + 1][j];
dp[i][j] = Math.max(take, noTake);
}
}
return dp[0][capacity];
}
public static void main(String[] args) {
int[] val = { 1, 1 };
int[] wt = { 2, 1 };
int capacity = 3;
System.out.println(knapSack(capacity, val, wt));
}
}
Python
# Python program to implement
# unbounded knapsack problem using tabulation
def knapSack(capacity, val, wt):
# 2D matrix for tabulation.
dp = [[0 for _ in range(capacity + 1)] for _ in range(len(val) + 1)]
# Calculate maximum profit for each
# item index and knapsack weight.
for i in range(len(val) - 1, -1, -1):
for j in range(1, capacity + 1):
take = 0
if j - wt[i] >= 0:
take = val[i] + dp[i][j - wt[i]]
noTake = dp[i + 1][j]
dp[i][j] = max(take, noTake)
return dp[0][capacity]
if __name__ == "__main__":
val = [1, 1]
wt = [2, 1]
capacity = 3
print(knapSack(capacity, val, wt))
C#
// C# program to implement
// unbounded knapsack problem using tabulation
using System;
class GfG {
static int knapSack(int capacity, int[] val, int[] wt) {
// 2D matrix for tabulation.
int[,] dp = new int[val.Length + 1, capacity + 1];
// Calculate maximum profit for each
// item index and knapsack weight.
for (int i = val.Length - 1; i >= 0; i--) {
for (int j = 1; j <= capacity; j++) {
int take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[i, j - wt[i]];
}
int noTake = dp[i + 1, j];
dp[i, j] = Math.Max(take, noTake);
}
}
return dp[0, capacity];
}
static void Main() {
int[] val = {1, 1};
int[] wt = {2, 1};
int capacity = 3;
Console.WriteLine(knapSack(capacity, val, wt));
}
}
JavaScript
// JavaScript program to implement
// unbounded knapsack problem using tabulation
function knapSack(capacity, val, wt) {
// 2D matrix for tabulation.
let dp = Array.from({ length: val.length + 1 }, () => Array(capacity + 1).fill(0));
// Calculate maximum profit for each
// item index and knapsack weight.
for (let i = val.length - 1; i >= 0; i--) {
for (let j = 1; j <= capacity; j++) {
let take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[i][j - wt[i]];
}
let noTake = dp[i + 1][j];
dp[i][j] = Math.max(take, noTake);
}
}
return dp[0][capacity];
}
const val = [1, 1];
const wt = [2, 1];
const capacity = 3;
console.log(knapSack(capacity, val, wt));
Using Space Optimized DP – O(n*capacity) Time and O(capacity) Space
The idea is store only the next row values. We can observe that for a given index i, its value depends only on current (i) and next (i+1) row. So only store these values and update them after each step.
C++
// C++ program to implement
// unbounded knapsack problem using space optimised
#include <bits/stdc++.h>
using namespace std;
int knapSack(int capacity, vector<int> &val, vector<int> &wt) {
// 1D matrix for tabulation.
vector<int> dp(capacity + 1, 0);
// Calculate maximum profit for each
// item index and knapsack weight.
for (int i = val.size() - 1; i >= 0; i--) {
for (int j = 1; j <= capacity; j++) {
int take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[j - wt[i]];
}
int noTake = dp[j];
dp[j] = max(take, noTake);
}
}
return dp[capacity];
}
int main() {
vector<int> val = {1, 1}, wt = {2, 1};
int capacity = 3;
cout << knapSack(capacity, val, wt);
}
Java
// Java program to implement
// unbounded knapsack problem using space optimised
class GfG {
static int knapSack(int capacity, int[] val, int[] wt) {
// 1D matrix for tabulation.
int[] dp = new int[capacity + 1];
// Calculate maximum profit for each
// item index and knapsack weight.
for (int i = val.length - 1; i >= 0; i--) {
for (int j = 1; j <= capacity; j++) {
int take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[j - wt[i]];
}
int noTake = dp[j];
dp[j] = Math.max(take, noTake);
}
}
return dp[capacity];
}
public static void main(String[] args) {
int[] val = { 1, 1 };
int[] wt = { 2, 1 };
int capacity = 3;
System.out.println(knapSack(capacity, val, wt));
}
}
Python
# Python program to implement
# unbounded knapsack problem using space optimised
def knapSack(capacity, val, wt):
# 1D matrix for tabulation.
dp = [0] * (capacity + 1)
# Calculate maximum profit for each
# item index and knapsack weight.
for i in range(len(val) - 1, -1, -1):
for j in range(1, capacity + 1):
take = 0
if j - wt[i] >= 0:
take = val[i] + dp[j - wt[i]]
noTake = dp[j]
dp[j] = max(take, noTake)
return dp[capacity]
if __name__ == "__main__":
val = [1, 1]
wt = [2, 1]
capacity = 3
print(knapSack(capacity, val, wt))
C#
// C# program to implement
// unbounded knapsack problem using space optimised
using System;
class GfG {
static int knapSack(int capacity, int[] val, int[] wt) {
// 1D matrix for tabulation.
int[] dp = new int[capacity + 1];
// Calculate maximum profit for each
// item index and knapsack weight.
for (int i = val.Length - 1; i >= 0; i--) {
for (int j = 1; j <= capacity; j++) {
int take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[j - wt[i]];
}
int noTake = dp[j];
dp[j] = Math.Max(take, noTake);
}
}
return dp[capacity];
}
static void Main() {
int[] val = { 1, 1 };
int[] wt = { 2, 1 };
int capacity = 3;
Console.WriteLine(knapSack(capacity, val, wt));
}
}
JavaScript
// JavaScript program to implement
// unbounded knapsack problem using space optimised
function knapSack(capacity, val, wt) {
// 1D matrix for tabulation.
let dp = Array(capacity + 1).fill(0);
// Calculate maximum profit for each
// item index and knapsack weight.
for (let i = val.length - 1; i >= 0; i--) {
for (let j = 1; j <= capacity; j++) {
let take = 0;
if (j - wt[i] >= 0) {
take = val[i] + dp[j - wt[i]];
}
let noTake = dp[j];
dp[j] = Math.max(take, noTake);
}
}
return dp[capacity];
}
const val = [1, 1];
const wt = [2, 1];
const capacity = 3;
console.log(knapSack(capacity, val, wt));
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem