Minimum Cost Polygon Triangulation
Last Updated :
23 Jul, 2025
A triangulation of a convex polygon is formed by drawing diagonals between non-adjacent vertices (corners) such that the diagonals never intersect. The problem is to find the cost of triangulation with the minimum cost. The cost of a triangulation is sum of the weights of its component triangles. Weight of each triangle is its perimeter (sum of lengths of all sides)
See following example taken from this source.

Two triangulations of the same convex pentagon. The triangulation on the left has a cost of 8 + 2?2 + 2?5 (approximately 15.30), the one on the right has a cost of 4 + 2?2 + 4?5 (approximately 15.77).
This problem has recursive substructure. The idea is to divide the polygon into three parts: a single triangle, the sub-polygon to the left, and the sub-polygon to the right. We try all possible divisions like this and find the one that minimizes the cost of the triangle plus the cost of the triangulation of the two sub-polygons.
Let Minimum Cost of triangulation of vertices from i to j be minCost(i, j)
If j < i + 2 Then
minCost(i, j) = 0
Else
minCost(i, j) = Min { minCost(i, k) + minCost(k, j) + cost(i, k, j) }
Here k varies from 'i+1' to 'j-1'
Cost of a triangle formed by edges (i, j), (j, k) and (k, i) is
cost(i, j, k) = dist(i, j) + dist(j, k) + dist(k, i)
Following is implementation of above naive recursive formula.
C++
// Recursive implementation for minimum cost convex polygon triangulation
#include <iostream>
#include <cmath>
#define MAX 1000000.0
using namespace std;
// Structure of a point in 2D plane
struct Point
{
int x, y;
};
// Utility function to find minimum of two double values
double min(double x, double y)
{
return (x <= y)? x : y;
}
// A utility function to find distance between two points in a plane
double dist(Point p1, Point p2)
{
return sqrt((p1.x - p2.x)*(p1.x - p2.x) +
(p1.y - p2.y)*(p1.y - p2.y));
}
// A utility function to find cost of a triangle. The cost is considered
// as perimeter (sum of lengths of all edges) of the triangle
double cost(Point points[], int i, int j, int k)
{
Point p1 = points[i], p2 = points[j], p3 = points[k];
return dist(p1, p2) + dist(p2, p3) + dist(p3, p1);
}
// A recursive function to find minimum cost of polygon triangulation
// The polygon is represented by points[i..j].
double mTC(Point points[], int i, int j)
{
// There must be at least three points between i and j
// (including i and j)
if (j < i+2)
return 0;
// Initialize result as infinite
double res = MAX;
// Find minimum triangulation by considering all
for (int k=i+1; k<j; k++)
res = min(res, (mTC(points, i, k) + mTC(points, k, j) +
cost(points, i, k, j)));
return res;
}
// Driver program to test above functions
int main()
{
Point points[] = {{0, 0}, {1, 0}, {2, 1}, {1, 2}, {0, 2}};
int n = sizeof(points)/sizeof(points[0]);
cout << mTC(points, 0, n-1);
return 0;
}
Java
// Class to store a point in the Euclidean plane
class Point
{
int x, y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
// Utility function to return the distance between two
// vertices in a 2-dimensional plane
public double dist(Point p)
{
// The distance between vertices `(x1, y1)` & `(x2,
// y2)` is `?((x2 ? x1) ^ 2 + (y2 ? y1) ^ 2)`
return Math.sqrt((this.x - p.x) * (this.x - p.x)
+ (this.y - p.y) * (this.y - p.y));
}
}
class GFG
{
// Function to calculate the weight of optimal
// triangulation of a convex polygon represented by a
// given set of vertices `vertices[i..j]`
public static double MWT(Point[] vertices, int i, int j)
{
// If the polygon has less than 3 vertices,
// triangulation is not possible
if (j < i + 2)
{
return 0;
}
// keep track of the total weight of the minimum
// weight triangulation of `MWT(i,j)`
double cost = Double.MAX_VALUE;
// consider all possible triangles `ikj` within the
// polygon
for (int k = i + 1; k <= j - 1; k++)
{
// The weight of a triangulation is the length
// of perimeter of the triangle
double weight = vertices[i].dist(vertices[j])
+ vertices[j].dist(vertices[k])
+ vertices[k].dist(vertices[i]);
// choose the vertex `k` that leads to the
// minimum total weight
cost = Double.min(cost,
weight + MWT(vertices, i, k)
+ MWT(vertices, k, j));
}
return cost;
}
// Driver code
public static void main(String[] args)
{
// vertices are given in clockwise order
Point[] vertices
= { new Point(0, 0), new Point(2, 0),
new Point(2, 1), new Point(1, 2),
new Point(0, 1) };
System.out.println(MWT(vertices,
0, vertices.length - 1));
}
}
// This code is contributed by Priiyadarshini Kumari
Python3
# Recursive implementation for minimum
# cost convex polygon triangulation
from math import sqrt
MAX = 1000000.0
# A utility function to find distance
# between two points in a plane
def dist(p1, p2):
return sqrt((p1[0] - p2[0])*(p1[0] - p2[0]) + \
(p1[1] - p2[1])*(p1[1] - p2[1]))
# A utility function to find cost of
# a triangle. The cost is considered
# as perimeter (sum of lengths of all edges)
# of the triangle
def cost(points, i, j, k):
p1 = points[i]
p2 = points[j]
p3 = points[k]
return dist(p1, p2) + dist(p2, p3) + dist(p3, p1)
# A recursive function to find minimum
# cost of polygon triangulation
# The polygon is represented by points[i..j].
def mTC(points, i, j):
# There must be at least three points between i and j
# (including i and j)
if (j < i + 2):
return 0
# Initialize result as infinite
res = MAX
# Find minimum triangulation by considering all
for k in range(i + 1, j):
res = min(res, (mTC(points, i, k) + \
mTC(points, k, j) + \
cost(points, i, k, j)))
return round(res, 4)
# Driver code
points = [[0, 0], [1, 0], [2, 1], [1, 2], [0, 2]]
n = len(points)
print(mTC(points, 0, n-1))
# This code is contributed by SHUBHAMSINGH10
C#
using System;
using System.Collections.Generic;
// Class to store a point in the Euclidean plane
public class Point {
public int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
// Utility function to return the distance between two
// vertices in a 2-dimensional plane
public double dist(Point p) {
// The distance between vertices `(x1, y1)` & `(x2,
// y2)` is `?((x2 ? x1) ^ 2 + (y2 ? y1) ^ 2)`
return Math.Sqrt((this.x - p.x) * (this.x - p.x) +
(this.y - p.y) * (this.y - p.y));
}
}
public class GFG {
// Function to calculate the weight of optimal
// triangulation of a convex polygon represented by a
// given set of vertices `vertices[i..j]`
public static double MWT(Point[] vertices, int i, int j) {
// If the polygon has less than 3 vertices,
// triangulation is not possible
if (j < i + 2) {
return 0;
}
// keep track of the total weight of the minimum
// weight triangulation of `MWT(i,j)`
double cost = 9999999999999.09;
// consider all possible triangles `ikj` within the
// polygon
for (int k = i + 1; k <= j - 1; k++) {
// The weight of a triangulation is the length
// of perimeter of the triangle
double weight = vertices[i].dist(vertices[j]) +
vertices[j].dist(vertices[k])
+ vertices[k].dist(vertices[i]);
// choose the vertex `k` that leads to the
// minimum total weight
cost = Math.Min(cost, weight +
MWT(vertices, i, k) +
MWT(vertices, k, j));
}
return Math.Round(cost,4);
}
// Driver code
public static void Main(String[] args) {
// vertices are given in clockwise order
Point[] vertices = { new Point(0, 0),
new Point(2, 0),
new Point(2, 1),
new Point(1, 2),
new Point(0, 1) };
Console.WriteLine(MWT(vertices, 0, vertices.Length - 1));
}
}
// This code is contributed by gauravrajput1
JavaScript
// A JavaScript program for a
// Recursive implementation for minimum cost convex polygon triangulation
const MAX = 1.79769e+308;
// Utility function to find minimum of two double values
function min(x, y)
{
return (x <= y)? x : y;
}
// A utility function to find distance between two points in a plane
function dist(p1, p2)
{
return Math.sqrt((p1[0] - p2[0])*(p1[0] - p2[0]) + (p1[1] - p2[1])*(p1[1] - p2[1]));
}
// A utility function to find cost of a triangle. The cost is considered
// as perimeter (sum of lengths of all edges) of the triangle
function cost(points, i, j, k)
{
p1 = points[i], p2 = points[j], p3 = points[k];
return dist(p1, p2) + dist(p2, p3) + dist(p3, p1);
}
// A recursive function to find minimum cost of polygon triangulation
// The polygon is represented by points[i..j].
function mTC(points, i, j)
{
// There must be at least three points between i and j
// (including i and j)
if (j < i+2){
return 0;
}
// Initialize result as infinite
let res = MAX;
// Find minimum triangulation by considering all
for (let k=i+1; k<j; k++){
res = min(res, (mTC(points, i, k) + mTC(points, k, j) + cost(points, i, k, j)));
}
return res;
}
// Driver program to test above functions
{
let points = [[0, 0], [1, 0], [2, 1], [1, 2],[0, 2]]
let n = points.length;
console.log(mTC(points, 0, n-1));
}
// The code is contributed by Nidhi Goel
Output:
15.3006
Time Complexity: O(2n)
Space Complexity: O(n) for the recursive stack space.
The above problem is similar to Matrix Chain Multiplication. The following is recursion tree for mTC(points[], 0, 4).

It can be easily seen in the above recursion tree that the problem has many overlapping subproblems. Since the problem has both properties: Optimal Substructure and Overlapping Subproblems, it can be efficiently solved using dynamic programming.
Following is C++ implementation of dynamic programming solution.
C++
// A Dynamic Programming based program to find minimum cost of convex
// polygon triangulation
#include <iostream>
#include <cmath>
#define MAX 1000000.0
using namespace std;
// Structure of a point in 2D plane
struct Point
{
int x, y;
};
// Utility function to find minimum of two double values
double min(double x, double y)
{
return (x <= y)? x : y;
}
// A utility function to find distance between two points in a plane
double dist(Point p1, Point p2)
{
return sqrt((p1.x - p2.x)*(p1.x - p2.x) +
(p1.y - p2.y)*(p1.y - p2.y));
}
// A utility function to find cost of a triangle. The cost is considered
// as perimeter (sum of lengths of all edges) of the triangle
double cost(Point points[], int i, int j, int k)
{
Point p1 = points[i], p2 = points[j], p3 = points[k];
return dist(p1, p2) + dist(p2, p3) + dist(p3, p1);
}
// A Dynamic programming based function to find minimum cost for convex
// polygon triangulation.
double mTCDP(Point points[], int n)
{
// There must be at least 3 points to form a triangle
if (n < 3)
return 0;
// table to store results of subproblems. table[i][j] stores cost of
// triangulation of points from i to j. The entry table[0][n-1] stores
// the final result.
double table[n][n];
// Fill table using above recursive formula. Note that the table
// is filled in diagonal fashion i.e., from diagonal elements to
// table[0][n-1] which is the result.
for (int gap = 0; gap < n; gap++)
{
for (int i = 0, j = gap; j < n; i++, j++)
{
if (j < i+2)
table[i][j] = 0.0;
else
{
table[i][j] = MAX;
for (int k = i+1; k < j; k++)
{
double val = table[i][k] + table[k][j] + cost(points,i,j,k);
if (table[i][j] > val)
table[i][j] = val;
}
}
}
}
return table[0][n-1];
}
// Driver program to test above functions
int main()
{
Point points[] = {{0, 0}, {1, 0}, {2, 1}, {1, 2}, {0, 2}};
int n = sizeof(points)/sizeof(points[0]);
cout << mTCDP(points, n);
return 0;
}
Java
// A Dynamic Programming based program to find minimum cost
// of convex polygon triangulation
import java.util.*;
class GFG
{
// Structure of a point in 2D plane
static class Point {
int x, y;
Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
// Utility function to find minimum of two double values
static double min(double x, double y)
{
return (x <= y) ? x : y;
}
// A utility function to find distance between two
// points in a plane
static double dist(Point p1, Point p2)
{
return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x)
+ (p1.y - p2.y) * (p1.y - p2.y));
}
// A utility function to find cost of a triangle. The
// cost is considered as perimeter (sum of lengths of
// all edges) of the triangle
static double cost(Point points[], int i, int j, int k)
{
Point p1 = points[i], p2 = points[j],
p3 = points[k];
return dist(p1, p2) + dist(p2, p3) + dist(p3, p1);
}
// A Dynamic programming based function to find minimum
// cost for convex polygon triangulation.
static double mTCDP(Point points[], int n)
{
// There must be at least 3 points to form a
// triangle
if (n < 3)
return 0;
// table to store results of subproblems.
// table[i][j] stores cost of triangulation of
// points from i to j. The entry table[0][n-1]
// stores the final result.
double[][] table = new double[n][n];
// Fill table using above recursive formula. Note
// that the table is filled in diagonal fashion
// i.e., from diagonal elements to table[0][n-1]
// which is the result.
for (int gap = 0; gap < n; gap++) {
for (int i = 0, j = gap; j < n; i++, j++) {
if (j < i + 2)
table[i][j] = 0.0;
else {
table[i][j] = 1000000.0;
for (int k = i + 1; k < j; k++) {
double val
= table[i][k] + table[k][j]
+ cost(points, i, j, k);
if (table[i][j] > val)
table[i][j] = val;
}
}
}
}
return table[0][n - 1];
}
// Driver program to test above functions
public static void main(String[] args)
{
Point[] points = { new Point(0, 0), new Point(1, 0),
new Point(2, 1), new Point(1, 2),
new Point(0, 2) };
int n = points.length;
System.out.println(mTCDP(points, n));
}
}
// This code is contributed by Karandeep Singh
Python
# A Dynamic Programming based program to find minimum cost
# of convex polygon triangulation
import math
class GFG:
# Structure of a point in 2D plane
class Point:
x = 0
y = 0
def __init__(self, x, y):
self.x = x
self.y = y
# Utility function to find minimum of two double values
@staticmethod
def min(x, y):
return x if (x <= y) else y
# A utility function to find distance between two
# points in a plane
@staticmethod
def dist(p1, p2):
return math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))
# A utility function to find cost of a triangle. The
# cost is considered as perimeter (sum of lengths of
# all edges) of the triangle
@staticmethod
def cost(points, i, j, k):
p1 = points[i]
p2 = points[j]
p3 = points[k]
return GFG.dist(p1, p2) + GFG.dist(p2, p3) + GFG.dist(p3, p1)
# A Dynamic programming based function to find minimum
# cost for convex polygon triangulation.
@staticmethod
def mTCDP(points, n):
# There must be at least 3 points to form a
# triangle
if (n < 3):
return 0
# table to store results of subproblems.
# table[i][j] stores cost of triangulation of
# points from i to j. The entry table[0][n-1]
# stores the final result.
table = [[0.0] * (n) for _ in range(n)]
# Fill table using above recursive formula. Note
# that the table is filled in diagonal fashion
# i.e., from diagonal elements to table[0][n-1]
# which is the result.
gap = 0
while (gap < n):
i = 0
j = gap
while (j < n):
if (j < i + 2):
table[i][j] = 0.0
else:
table[i][j] = 1000000.0
k = i + 1
while (k < j):
val = table[i][k] + table[k][j] + \
GFG.cost(points, i, j, k)
if (table[i][j] > val):
table[i][j] = val
k += 1
i += 1
j += 1
gap += 1
return table[0][n - 1]
# Driver program to test above functions
if __name__ == "__main__":
points = [GFG.Point(0, 0), GFG.Point(1, 0), GFG.Point(
2, 1), GFG.Point(1, 2), GFG.Point(0, 2)]
n = len(points)
print(GFG.mTCDP(points, n))
# This code is contributed by Aarti_Rathi
C#
using System;
// A Dynamic Programming based program to find minimum cost
// of convex polygon triangulation
// Structure of a point in 2D plane
public class Point {
public int x;
public int y;
}
public static class Globals {
public const double MAX = 1000000.0;
// Utility function to find minimum of two double values
public static double min(double x, double y)
{
return (x <= y) ? x : y;
}
// A utility function to find distance between two
// points in a plane
public static double dist(Point p1, Point p2)
{
return Math.Sqrt((p1.x - p2.x) * (p1.x - p2.x)
+ (p1.y - p2.y) * (p1.y - p2.y));
}
// A utility function to find cost of a triangle. The
// cost is considered as perimeter (sum of lengths of
// all edges) of the triangle
public static double cost(Point[] points, int i, int j,
int k)
{
Point p1 = points[i];
Point p2 = points[j];
Point p3 = points[k];
return (dist(p1, p2) + dist(p2, p3) + dist(p3, p1));
}
// A Dynamic programming based function to find minimum
// cost for convex polygon triangulation.
public static double mTCDP(Point[] points, int n)
{
// There must be at least 3 points to form a
// triangle
if (n < 3) {
return 0;
}
// table to store results of subproblems.
// table[i][j] stores cost of triangulation of
// points from i to j. The entry table[0][n-1]
// stores the final result.
double[, ] table = new double[n, n];
;
// Fill table using above recursive formula. Note
// that the table is filled in diagonal fashion
// i.e., from diagonal elements to table[0][n-1]
// which is the result.
for (int gap = 0; gap < n; gap++) {
for (int i = 0, j = gap; j < n; i++, j++) {
if (j < i + 2) {
table[i, j] = 0.0;
}
else {
table[i, j] = MAX;
for (int k = i + 1; k < j; k++) {
double val
= table[i, k] + table[k, j]
+ cost(points, i, j, k);
if (table[i, j] > val) {
table[i, j] = val;
}
}
}
}
}
return table[0, n - 1];
}
// Driver program to test above functions
public static void Main()
{
Point[] points = { new Point(){ x = 0, y = 0 },
new Point(){ x = 1, y = 0 },
new Point(){ x = 2, y = 1 },
new Point(){ x = 1, y = 2 },
new Point(){ x = 0, y = 2 } };
int n = points.Length;
Console.Write(mTCDP(points, n));
}
}
// This code is contributed by Aarti_Rathi
JavaScript
// A Dynamic Programming based program to
// find minimum cost of convex polygon triangulation
const MAX = 1000000.0;
// Structure of a point in 2D plane
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
// Utility function to find minimum of two double values
function min(x, y) {
return x <= y ? x : y;
}
// A utility function to find distance between two points in a plane
function dist(p1, p2) {
return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}
// A utility function to find cost of a triangle. The cost is considered as perimeter (sum of lengths of all edges) of the triangle
function cost(points, i, j, k) {
let p1 = points[i],
p2 = points[j],
p3 = points[k];
return dist(p1, p2) + dist(p2, p3) + dist(p3, p1);
}
// A Dynamic programming based function to find minimum cost for convex polygon triangulation.
function mTCDP(points, n) {
// There must be at least 3 points to form a triangle
if (n < 3) return 0;
// table to store results of subproblems.
// table[i][j] stores cost of triangulation
// of points from i to j. The entry table[0][n-1] stores the final result.
let table = new Array(n);
for (let i = 0; i < n; i++) {
table[i] = new Array(n);
}
// Fill table using above recursive formula.
// Note that the table is filled in
// diagonal fashion i.e., from diagonal
// elements to table[0][n-1] which is the result.
for (let gap = 0; gap < n; gap++) {
for (let i = 0, j = gap; j < n; i++, j++) {
if (j < i + 2) {
table[i][j] = 0;
} else {
table[i][j] = MAX;
for (let k = i + 1; k < j; k++) {
let val = table[i][k] + table[k][j] + cost(points, i, j, k);
if (table[i][j] > val) {
table[i][j] = val;
}
}
}
}
}
return table[0][n - 1];
}
// Driver program to test above functions
let points = [new Point(0, 0), new Point(1, 0), new Point(2, 1), new Point(1, 2), new Point(0, 2)];
let n = points.length;
let result = mTCDP(points, n);
console.log(Math.ceil(result * 10000) / 10000);
// This code is contributed by lokeshpotta20.
Output:
15.3006
Time complexity of the above dynamic programming solution is O(n3).
Auxiliary Space: O(n*n)
Please note that the above implementations assume that the points of convex polygon are given in order (either clockwise or anticlockwise)
Exercise:
Extend the above solution to print triangulation also. For the above example, the optimal triangulation is 0 3 4, 0 1 3, and 1 2 3.
Sources:
https://www.cs.utexas.edu/~djimenez/utsa/cs3343/lecture12.html
http://www.cs.utoronto.ca/~heap/Courses/270F02/A4/chains/node2.html
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