Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
Last Updated :
23 Jul, 2025
Given an arbitrary binary tree, your task is to convert it to a binary tree that holds Children Sum Property, by incrementing the data values of any node.
Note: The structure of the tree can't be changed and the node values can't be decremented. Also, there exist multiple possible answers.
Example:
Input: 50
/ \
7 2
/ \ / \
3 5 1 30
Output: 50
/ \
19 31
/ \ / \
14 5 1 30
Explanation: For every node, now its value is equal to the sum of values of its immediate left and right child. One more possible solution is:
79
/ \
48 31
/ \ / \
43 5 1 30
[Naive Approach] - O(n ^ 2) Time and O(h) Space
The idea is to traverse the given tree in post order to firstly convert the left and right children to hold the children sum property and then change the parent node.
After converting the child nodes, find the difference diff between node's data and sum of children nodes i.e. diff = node’s children sum - node’s data.
There are three possibilities:
- diff == 0: Nothing needs to be done, as the node follows the child sum property:
- diff > 0: Nodes data is smaller than sum of children node's data, thus increment the node's data by diff.
- diff < 0: Nodes data is greater than sum of children node's data, then increment one child's data.
Incrementing a child changes the subtree’s children sum property so we need to change left subtree also. So we recursively increment the left child. If left child is empty then we recursively call increment() for right child.
Let us run the algorithm for the given example:
50
/ \
7 2
/ \ / \
3 5 1 30
First convert the left subtree (increment 7 to 8).
50
/ \
8 2
/ \ / \
3 5 1 30
Then convert the right subtree (increment 2 to 31)
50
/ \
8 31
/ \ / \
3 5 1 30
Now convert the root, we have to increment left subtree for converting the root.
50
/ \
19 31
/ \ / \
14 5 1 30
Please note the last step – we have incremented 8 to 19, and to fix the subtree we have incremented 3 to 14.
C++
#include<bits/stdc++.h>
using namespace std;
// Node structure
class Node {
public:
int data;
Node* left;
Node* right;
Node(int data) {
this->data = data;
this->left = nullptr;
this->right = nullptr;
}
};
// Function to increment the left subtree
void increment(Node* cur, int diff) {
// If left child is not
// nullptr then increment it
if(cur->left != nullptr) {
cur->left->data = cur->left->data + diff;
// Recursively call to fix
// the descendants of Node->left
increment(cur->left, diff);
}
// Else increment right child
else if (cur->right != nullptr) {
cur->right->data = cur->right->data + diff;
// Recursively call to fix
// the descendants of Node->right
increment(cur->right, diff);
}
}
// Function to modify a tree
// to hold children sum property
void convertTree(Node* cur) {
// If tree is empty or it's a
// leaf Node then return true
if (cur == nullptr || (cur->left == nullptr &&
cur->right == nullptr))
return;
// convert left and right subtrees first
convertTree(cur->left);
convertTree(cur->right);
int leftData = 0, rightData = 0;
// update left and right child data
if (cur->left != nullptr)
leftData = cur->left->data;
if (cur->right != nullptr)
rightData = cur->right->data;
// get the diff of Node's data and children sum
int diff = leftData + rightData - cur->data;
// if Node's children sum is
// greater than the Node's data
if (diff > 0)
cur->data = cur->data + diff;
// else if Node's data is greater than
// children sum then increment subtree
else if (diff < 0)
increment(cur, abs(diff));
}
// prints the inorder traversal of tree
void printInorder(Node* cur) {
if (cur == nullptr)
return;
printInorder(cur->left);
cout<<cur->data<<" ";
printInorder(cur->right);
}
int main() {
// construct the binary tree
/*
50
/ \
7 2
/ \ / \
3 5 1 30 */
Node *root = new Node(50);
root->left = new Node(7);
root->right = new Node(2);
root->left->left = new Node(3);
root->left->right = new Node(5);
root->right->left = new Node(1);
root->right->right = new Node(30);
printInorder(root);
cout<<endl;
convertTree(root);
printInorder(root);
return 0;
}
Java
// Node structure
class Node {
int data;
Node left;
Node right;
Node(int data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Function to increment the left subtree
class GfG {
// Function to increment the left subtree
static void increment(Node cur, int diff) {
// If left child is not
// null then increment it
if (cur.left != null) {
cur.left.data = cur.left.data + diff;
// Recursively call to fix
// the descendants of Node->left
increment(cur.left, diff);
}
// Else increment right child
else if (cur.right != null) {
cur.right.data = cur.right.data + diff;
// Recursively call to fix
// the descendants of Node->right
increment(cur.right, diff);
}
}
// Function to modify a tree
// to hold children sum property
static void convertTree(Node cur) {
// If tree is empty or it's a
// leaf Node then return true
if (cur == null || (cur.left == null && cur.right == null))
return;
// convert left and right subtrees first
convertTree(cur.left);
convertTree(cur.right);
int leftData = 0, rightData = 0;
// update left and right child data
if (cur.left != null)
leftData = cur.left.data;
if (cur.right != null)
rightData = cur.right.data;
// get the diff of Node's data and children sum
int diff = leftData + rightData - cur.data;
// if Node's children sum is
// greater than the Node's data
if (diff > 0)
cur.data = cur.data + diff;
// else if Node's data is greater than
// children sum then increment subtree
else if (diff < 0)
increment(cur, Math.abs(diff));
}
// prints the inorder traversal of tree
static void printInorder(Node cur) {
if (cur == null)
return;
printInorder(cur.left);
System.out.print(cur.data + " ");
printInorder(cur.right);
}
public static void main(String[] args) {
// construct the binary tree
/*
50
/ \
7 2
/ \ / \
3 5 1 30 */
Node root = new Node(50);
root.left = new Node(7);
root.right = new Node(2);
root.left.left = new Node(3);
root.left.right = new Node(5);
root.right.left = new Node(1);
root.right.right = new Node(30);
printInorder(root);
System.out.println();
convertTree(root);
printInorder(root);
}
}
Python
# Node structure
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
# Function to increment the left subtree
def increment(cur, diff):
# If left child is not
# None then increment it
if cur.left is not None:
cur.left.data = cur.left.data + diff
# Recursively call to fix
# the descendants of Node->left
increment(cur.left, diff)
# Else increment right child
elif cur.right is not None:
cur.right.data = cur.right.data + diff
# Recursively call to fix
# the descendants of Node->right
increment(cur.right, diff)
# Function to modify a tree
# to hold children sum property
def convertTree(cur):
# If tree is empty or it's a
# leaf Node then return true
if cur is None or (cur.left is None and cur.right is None):
return
# convert left and right subtrees first
convertTree(cur.left)
convertTree(cur.right)
leftData = 0
rightData = 0
# update left and right child data
if cur.left is not None:
leftData = cur.left.data
if cur.right is not None:
rightData = cur.right.data
# get the diff of Node's data and children sum
diff = leftData + rightData - cur.data
# if Node's children sum is
# greater than the Node's data
if diff > 0:
cur.data = cur.data + diff
# else if Node's data is greater than
# children sum then increment subtree
elif diff < 0:
increment(cur, abs(diff))
# prints the inorder traversal of tree
def printInorder(cur):
if cur is None:
return
printInorder(cur.left)
print(cur.data, end=" ")
printInorder(cur.right)
if __name__ == "__main__":
# construct the binary tree
# 50
# / \
# 7 2
# / \ / \
#3 5 1 30
root = Node(50)
root.left = Node(7)
root.right = Node(2)
root.left.left = Node(3)
root.left.right = Node(5)
root.right.left = Node(1)
root.right.right = Node(30)
printInorder(root)
print()
convertTree(root)
printInorder(root)
C#
// Node structure
using System;
using System.Collections.Generic;
class Node {
public int data;
public Node left;
public Node right;
public Node(int data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Function to increment the left subtree
class GfG {
// Function to increment the left subtree
static void increment(Node cur, int diff) {
// If left child is not
// null then increment it
if (cur.left != null) {
cur.left.data = cur.left.data + diff;
// Recursively call to fix
// the descendants of Node->left
increment(cur.left, diff);
}
// Else increment right child
else if (cur.right != null) {
cur.right.data = cur.right.data + diff;
// Recursively call to fix
// the descendants of Node->right
increment(cur.right, diff);
}
}
// Function to modify a tree
// to hold children sum property
static void convertTree(Node cur) {
// If tree is empty or it's a
// leaf Node then return true
if (cur == null || (cur.left == null && cur.right == null))
return;
// convert left and right subtrees first
convertTree(cur.left);
convertTree(cur.right);
int leftData = 0, rightData = 0;
// update left and right child data
if (cur.left != null)
leftData = cur.left.data;
if (cur.right != null)
rightData = cur.right.data;
// get the diff of Node's data and children sum
int diff = leftData + rightData - cur.data;
// if Node's children sum is
// greater than the Node's data
if (diff > 0)
cur.data = cur.data + diff;
// else if Node's data is greater than
// children sum then increment subtree
else if (diff < 0)
increment(cur, Math.Abs(diff));
}
// prints the inorder traversal of tree
static void printInorder(Node cur) {
if (cur == null)
return;
printInorder(cur.left);
Console.Write(cur.data + " ");
printInorder(cur.right);
}
static void Main() {
// construct the binary tree
/*
50
/ \
7 2
/ \ / \
3 5 1 30 */
Node root = new Node(50);
root.left = new Node(7);
root.right = new Node(2);
root.left.left = new Node(3);
root.left.right = new Node(5);
root.right.left = new Node(1);
root.right.right = new Node(30);
printInorder(root);
Console.WriteLine();
convertTree(root);
printInorder(root);
}
}
JavaScript
// Node structure
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Function to increment the left subtree
function increment(cur, diff) {
// If left child is not
// null then increment it
if (cur.left !== null) {
cur.left.data = cur.left.data + diff;
// Recursively call to fix
// the descendants of Node->left
increment(cur.left, diff);
}
// Else increment right child
else if (cur.right !== null) {
cur.right.data = cur.right.data + diff;
// Recursively call to fix
// the descendants of Node->right
increment(cur.right, diff);
}
}
// Function to modify a tree
// to hold children sum property
function convertTree(cur) {
// If tree is empty or it's a
// leaf Node then return true
if (cur === null || (cur.left === null && cur.right === null))
return;
// convert left and right subtrees first
convertTree(cur.left);
convertTree(cur.right);
let leftData = 0, rightData = 0;
// update left and right child data
if (cur.left !== null)
leftData = cur.left.data;
if (cur.right !== null)
rightData = cur.right.data;
// get the diff of Node's data and children sum
let diff = leftData + rightData - cur.data;
// if Node's children sum is
// greater than the Node's data
if (diff > 0)
cur.data = cur.data + diff;
// else if Node's data is greater than
// children sum then increment subtree
else if (diff < 0)
increment(cur, Math.abs(diff));
}
// prints the inorder traversal of tree
function printInorder(cur) {
if (cur === null)
return;
printInorder(cur.left);
process.stdout.write(cur.data + " ");
printInorder(cur.right);
}
function main() {
// construct the binary tree
/*
50
/ \
7 2
/ \ / \
3 5 1 30 */
let root = new Node(50);
root.left = new Node(7);
root.right = new Node(2);
root.left.left = new Node(3);
root.left.right = new Node(5);
root.right.left = new Node(1);
root.right.right = new Node(30);
printInorder(root);
console.log("");
convertTree(root);
printInorder(root);
}
main();
Output3 7 5 50 1 2 30
14 19 5 50 1 31 30
Time Complexity: O(n ^ 2), worst case complexity is for a skewed tree such that nodes are in decreasing order from root to leaf.
Auxiliary Space : O(h) where h is the height of the binary tree.
[Expected Approach] - O(n) Time and O(h) Space
The idea is to modify the children nodes in top-down fashion while fix the children sum property in bottom-up fashion. To make sure that the parent's node data is not greater than sum of children nodes data, update the child nodes while going down the tree. And while returning sum the child nodes data and update the parent node's data accordingly.
Consider the following example:
50
/ \
7 2
/ \ / \
3 5 1 30
Here, the issue is having shortage while summing, like 1 + 30 =31 then 3 + 5 = 8 => 31+8 =39, but u cannot decrement 50 to 39 as per rule.
- So while going down the tree increase the value so to make sure we don't end up with shortage.
- Then all we need to do is, while returning, just sum the children and replace the parent node.
- At last, the children sum property holds TRUE. (As there is no restriction on the value needs to be minimum as such).
C++
#include<bits/stdc++.h>
using namespace std;
// Node structure
class Node {
public:
int data;
Node* left;
Node* right;
Node(int data) {
this->data = data;
this->left = nullptr;
this->right = nullptr;
}
};
// Function to modify a tree
// to hold children sum property
void convertTree(Node* root) {
// if root is null, return
if (!root) return;
// find the left and right child sum
int childSum = 0;
if (root->left)
childSum += root->left->data;
if (root->right)
childSum += root->right->data;
// if the root's data is less than
// the sum of its children
if (root->data < childSum) {
root->data = childSum;
}
// if the root's data is greater than
// the sum of its children
else if (root->data > childSum) {
int diff = root->data - childSum;
// if left child is not null
if (root->left)
root->left->data += diff;
// else if right child is not null
else if (root->right)
root->right->data += diff;
}
// modify the left and right subtree
convertTree(root->left);
convertTree(root->right);
// update the root's data to sum
// of child node's data
childSum = 0;
if (root->left)
childSum += root->left->data;
if (root->right)
childSum += root->right->data;
// if root is not leaf node
if(root->left || root->right)
root->data = childSum;
}
// prints the inorder traversal of tree
void printInorder(Node* cur) {
if (cur == nullptr)
return;
printInorder(cur->left);
cout<<cur->data<<" ";
printInorder(cur->right);
}
int main() {
// construct the binary tree
/*
50
/ \
7 2
/ \ / \
3 5 1 30 */
Node *root = new Node(50);
root->left = new Node(7);
root->right = new Node(2);
root->left->left = new Node(3);
root->left->right = new Node(5);
root->right->left = new Node(1);
root->right->right = new Node(30);
printInorder(root);
cout<<endl;
convertTree(root);
printInorder(root);
return 0;
}
Java
// Node structure
class Node {
int data;
Node left;
Node right;
Node(int data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Function to modify a tree
// to hold children sum property
class GfG {
static void convertTree(Node root) {
// if root is null, return
if (root == null)
return;
// find the left and right child sum
int childSum = 0;
if (root.left != null)
childSum += root.left.data;
if (root.right != null)
childSum += root.right.data;
// if the root's data is less than
// the sum of its children
if (root.data < childSum) {
root.data = childSum;
}
// if the root's data is greater than
// the sum of its children
else if (root.data > childSum) {
int diff = root.data - childSum;
// if left child is not null
if (root.left != null)
root.left.data += diff;
// else if right child is not null
else if (root.right != null)
root.right.data += diff;
}
// modify the left and right subtree
convertTree(root.left);
convertTree(root.right);
// update the root's data to sum
// of child node's data
childSum = 0;
if (root.left != null)
childSum += root.left.data;
if (root.right != null)
childSum += root.right.data;
// if root is not leaf node
if (root.left != null || root.right != null)
root.data = childSum;
}
static void printInorder(Node cur) {
if (cur == null)
return;
printInorder(cur.left);
System.out.print(cur.data + " ");
printInorder(cur.right);
}
public static void main(String[] args) {
Node root = new Node(50);
root.left = new Node(7);
root.right = new Node(2);
root.left.left = new Node(3);
root.left.right = new Node(5);
root.right.left = new Node(1);
root.right.right = new Node(30);
printInorder(root);
System.out.println();
convertTree(root);
printInorder(root);
}
}
Python
# Node structure
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
# Function to modify a tree
# to hold children sum property
def convertTree(root):
# if root is null, return
if root is None or (root.left is None and root.right is None):
return
# find the left and right child sum
childSum = 0
if root.left is not None:
childSum += root.left.data
if root.right is not None:
childSum += root.right.data
# if the root's data is less than
# the sum of its children
if root.data < childSum:
root.data = root.data + 0 + childSum
# if the root's data is greater than
# the sum of its children
elif root.data > childSum:
diff = root.data - childSum
# if left child is not null
if root.left is not None:
root.left.data = root.left.data + diff
# else if right child is not null
elif root.right is not None:
root.right.data = root.right.data + diff
# modify the left and right subtree
convertTree(root.left)
convertTree(root.right)
# update the root's data to sum
# of child node's data
childSum = 0
if root.left is not None:
childSum += root.left.data
if root.right is not None:
childSum += root.right.data
# if root is not leaf node
if root.left is not None or root.right is not None:
root.data = childSum
# prints the inorder traversal of tree
def printInorder(cur):
if cur is None:
return
printInorder(cur.left)
print(cur.data, end=" ")
printInorder(cur.right)
if __name__ == "__main__":
root = Node(50)
root.left = Node(7)
root.right = Node(2)
root.left.left = Node(3)
root.left.right = Node(5)
root.right.left = Node(1)
root.right.right = Node(30)
printInorder(root)
print()
convertTree(root)
printInorder(root)
C#
// Node structure
using System;
using System.Collections.Generic;
class Node {
public int data;
public Node left;
public Node right;
public Node(int data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Function to modify a tree
// to hold children sum property
class GfG {
static void convertTree(Node root) {
// if root is null, return
if (root == null || (root.left == null && root.right == null))
return;
// find the left and right child sum
int childSum = 0;
if (root.left != null)
childSum += root.left.data;
if (root.right != null)
childSum += root.right.data;
// if the root's data is less than
// the sum of its children
if (root.data < childSum)
root.data = root.data + 0 + childSum;
// else if the root's data is greater than
// the sum of its children
else if (root.data > childSum) {
int diff = root.data - childSum;
// if left child is not null
if (root.left != null)
root.left.data = root.left.data + diff;
// else if right child is not null
else if (root.right != null)
root.right.data = root.right.data + diff;
}
// modify the left and right subtree
convertTree(root.left);
convertTree(root.right);
// update the root's data to sum
// of child node's data
childSum = 0;
if (root.left != null)
childSum += root.left.data;
if (root.right != null)
childSum += root.right.data;
// if root is not leaf node
if (root.left != null || root.right != null)
root.data = childSum;
}
static void printInorder(Node cur) {
if (cur == null)
return;
printInorder(cur.left);
Console.Write(cur.data + " ");
printInorder(cur.right);
}
static void Main() {
Node root = new Node(50);
root.left = new Node(7);
root.right = new Node(2);
root.left.left = new Node(3);
root.left.right = new Node(5);
root.right.left = new Node(1);
root.right.right = new Node(30);
printInorder(root);
Console.WriteLine();
convertTree(root);
printInorder(root);
}
}
JavaScript
// Node structure
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Function to modify a tree
// to hold children sum property
function convertTree(root) {
// if root is null, return
if (root === null || (root.left === null && root.right === null))
return;
// find the left and right child sum
let childSum = 0;
if (root.left !== null)
childSum += root.left.data;
if (root.right !== null)
childSum += root.right.data;
// if the root's data is less than
// the sum of its children
if (root.data < childSum)
root.data = root.data + 0 + childSum;
// else if the root's data is greater than
// the sum of its children
else if (root.data > childSum) {
let diff = root.data - childSum;
// if left child is not null
if (root.left !== null)
root.left.data = root.left.data + diff;
// else if right child is not null
else if (root.right !== null)
root.right.data = root.right.data + diff;
}
// modify the left and right subtree
convertTree(root.left);
convertTree(root.right);
// update the root's data to sum
// of child node's data
childSum = 0;
if (root.left !== null)
childSum += root.left.data;
if (root.right !== null)
childSum += root.right.data;
// if root is not leaf node
if (root.left !== null || root.right !== null)
root.data = childSum;
}
// prints the inorder traversal of tree
function printInorder(cur) {
if (cur === null)
return;
printInorder(cur.left);
process.stdout.write(cur.data + " ");
printInorder(cur.right);
}
function main() {
let root = new Node(50);
root.left = new Node(7);
root.right = new Node(2);
root.left.left = new Node(3);
root.left.right = new Node(5);
root.right.left = new Node(1);
root.right.right = new Node(30);
printInorder(root);
console.log("");
convertTree(root);
printInorder(root);
}
main();
Output3 7 5 50 1 2 30
43 48 5 79 1 31 30
Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
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